2014년 12월 31일 수요일
Activeperl 에서 perk/Tk 를 이용하기.
https://code.activestate.com/ppm/Tk/
에서 정보를 참조함.
Windows 에서 perl 5.16 버전의 경우, Tk 를 지원한다고 적혀 있음.
그리고
Windows 의 command 창에서
ppm install Tk
를 실행시킴.
위 그림과 같이 설치가 완료됨.
그리고 같단한 Tk 예제를 실행시키니 정상적으로 실행됨을 확인했음.
2014년 12월 6일 토요일
Linux File Redirection
http://www.tldp.org/LDP/abs/html/io-redirection.html
https://www.digitalocean.com/community/tutorials/an-introduction-to-linux-i-o-redirection
파일 리다이렉션할 때 항상 헛갈리는 부분이 있었는데 검색을 통해 확실히 정리함.
( 위 사이트에 정리가 잘 되어 있었음. )
command &> filename
이건 stdout 과 stderr 을 모두 "filename" 이라는 파일로 redirection 하라는 의미.
command 2>&1
이건 file descriptor 2 번( stderr )을 file descriptor 1 번(stdout) 로 redirection 하라는 의미.
이것의 일반적인 표현은 command M>&N 즉 M 파일 서술자를 N 파일 서술자로 redirection 하라는 의미.
2014년 10월 9일 목요일
ddd 를 사용하여 메모리의 값 읽어보기.
참조 주소.
아래와 같이 printf 로 일일이 찍어보기 보다는,
귀찮더라도, ddd 를 사용하여 memory 의 주소를 지정하여 바로 값을 확인할 수 있는
방법을 익히자 라는 생각이 들었다.
#include
int main(int argc, char *argv[] )
{
unsigned short host_port = 0x1234;
unsigned short net__port ;
unsigned long host_addr = 0x12345678;
unsigned long net__addr;
net__port = htons( host_port );
printf("host port : %p, %#x\n", &host_port, host_port);
printf("net port : %p, %#x\n", &net__port, net__port);
printf("%p, %#x\n", &host_port , *( ( unsigned char *) &host_port ) );
printf("%p, %#x\n",( unsigned char *) &host_port + 1, *( ( unsigned char *) &host_port + 1) );
net__addr = htonl( host_addr );
printf("host addr : %p, %#lx\n", &host_addr, host_addr );
printf("net addr : %p, %#lx\n", &net__addr, net__addr );
printf("host addr + 0 : %p, %#x\n", &host_addr , *( (unsigned char * ) &host_addr ) );
printf("host addr + 1 : %p, %#x\n", (unsigned char * )&host_addr + 1, *( (unsigned char * ) &host_addr + 1 ) );
printf("host addr + 2 : %p, %#x\n", (unsigned char * )&host_addr + 2, *( (unsigned char * ) &host_addr + 2 ) );
printf("host addr + 3 : %p, %#x\n", (unsigned char * )&host_addr + 3, *( (unsigned char * ) &host_addr + 3 ) );
return 0;
}
http://www.delorie.com/gnu/docs/gdb/gdb_56.html
위 글을 보니
원하는 변수의 주소값을 알아서 x command 와 사용하면,
불편하게 printf 하지 않아도 되겠다 라는 생각이 들었다.
우선 g 옵션을 주어서 컴파일 하고,
ddd 를 구동시켰다.
1) 변수의 메모리 주소 확인하는 방법
print &변수명 : 변수 이름 앞에 & 를 붙이니 변수의 메모리 주소가 출력된다.
& 이 없으면 그 값이 출력된다.
크기는 하나의 byte 로 해서, 16진수로 해당 주소의 값을 출력하라는 의미이다.
x /ubx &host_port
와 같이 직접 메모리 주소를 적지 않고, 포인터를 이용해서
메모리의 주소값을 인자로 사용하는 것도 가능
(gdb) x /2ubx 0xbffff1be
0xbffff1be: 0x34 0x12
x /
Format letters
(octal),
x(hex),
d(decimal),
u(unsigned decimal),
t(binary),
f(float),
a(address),
i(instruction),
c(char) and
s(string).
Size letters are
b(byte),
h(halfword),
w(word),
g(giant, 8 bytes).
For example, x /32xw 0x400000 will dump 32 words (32 bit integers) starting at 0x400000. Note that you can also use registers in place of the address, if you prefix them with a $
아래와 같이 printf 로 일일이 찍어보기 보다는,
귀찮더라도, ddd 를 사용하여 memory 의 주소를 지정하여 바로 값을 확인할 수 있는
방법을 익히자 라는 생각이 들었다.
#include
int main(int argc, char *argv[] )
{
unsigned short host_port = 0x1234;
unsigned short net__port ;
unsigned long host_addr = 0x12345678;
unsigned long net__addr;
net__port = htons( host_port );
printf("host port : %p, %#x\n", &host_port, host_port);
printf("net port : %p, %#x\n", &net__port, net__port);
printf("%p, %#x\n", &host_port , *( ( unsigned char *) &host_port ) );
printf("%p, %#x\n",( unsigned char *) &host_port + 1, *( ( unsigned char *) &host_port + 1) );
net__addr = htonl( host_addr );
printf("host addr : %p, %#lx\n", &host_addr, host_addr );
printf("net addr : %p, %#lx\n", &net__addr, net__addr );
printf("host addr + 0 : %p, %#x\n", &host_addr , *( (unsigned char * ) &host_addr ) );
printf("host addr + 1 : %p, %#x\n", (unsigned char * )&host_addr + 1, *( (unsigned char * ) &host_addr + 1 ) );
printf("host addr + 2 : %p, %#x\n", (unsigned char * )&host_addr + 2, *( (unsigned char * ) &host_addr + 2 ) );
printf("host addr + 3 : %p, %#x\n", (unsigned char * )&host_addr + 3, *( (unsigned char * ) &host_addr + 3 ) );
return 0;
}
http://www.delorie.com/gnu/docs/gdb/gdb_56.html
위 글을 보니
원하는 변수의 주소값을 알아서 x command 와 사용하면,
불편하게 printf 하지 않아도 되겠다 라는 생각이 들었다.
우선 g 옵션을 주어서 컴파일 하고,
ddd 를 구동시켰다.
1) 변수의 메모리 주소 확인하는 방법
print &변수명 : 변수 이름 앞에 & 를 붙이니 변수의 메모리 주소가 출력된다.
& 이 없으면 그 값이 출력된다.
(gdb) print host_port
$2 = 4660
(gdb) print &host_port
$3 = (short unsigned int *) 0xbffff1be
(gdb) x /ub 0xbffff1be
0xbffff1be: 52
(gdb) x /ubx 0xbffff1be
0xbffff1be: 0x34
(gdb) x /ubx 0xbffff1bf
0xbffff1bf: 0x12
크기는 하나의 byte 로 해서, 16진수로 해당 주소의 값을 출력하라는 의미이다.
x /ubx &host_port
와 같이 직접 메모리 주소를 적지 않고, 포인터를 이용해서
메모리의 주소값을 인자로 사용하는 것도 가능
(gdb) x /2ubx 0xbffff1be
0xbffff1be: 0x34 0x12
1 byte 짜리 2 개를 출력하되, 16진수로.
0xbffff1be
0xbffff1bf
두 조소안에 있는 값이 출력.
x 명령어의 옵션
x /
Format letters
(octal),
x(hex),
d(decimal),
u(unsigned decimal),
t(binary),
f(float),
a(address),
i(instruction),
c(char) and
s(string).
Size letters are
b(byte),
h(halfword),
w(word),
g(giant, 8 bytes).
For example, x /32xw 0x400000 will dump 32 words (32 bit integers) starting at 0x400000. Note that you can also use registers in place of the address, if you prefix them with a $
n : the repeat count, 연속으로 출력할 갯수
t : display format
s : null 로 끝나는 문자열
i : machine instruction ... 이건 무슨 의미?
x : hexadecimal, 16진수.
u : unit size : 메모리 단위(크기)지정
b : byte
h : half words ( 2 bytes )
w: words ( 4 bytes )
g: giant words( 8 bytes )
참조 사이트
http://althing.cs.dartmouth.edu/local/www.acm.uiuc.edu/sigmil/RevEng/ch07.html
참조 사이트
http://althing.cs.dartmouth.edu/local/www.acm.uiuc.edu/sigmil/RevEng/ch07.html
피드 구독하기:
글 (Atom)