관심있는 것들 정리

gdb의 print 명령 본문

programming/Debugging

gdb의 print 명령

내공강화 2012. 2. 25. 14:54
gdb의 print 명령의 설명은 다음과 같다.

(gdb) help print
Print value of expression EXP.
Variables accessible are those of the lexical environment of the selected
stack frame, plus all those whose scope is global or an entire file.

$NUM gets previous value number NUM.  $ and $$ are the last two values.
$$NUM refers to NUM'th value back from the last one.
Names starting with $ refer to registers (with the values they would have
if the program were to return to the stack frame now selected, restoring
all registers saved by frames farther in) or else to debugger
"convenience" variables (any such name not a known register).
Use assignment expressions to give values to convenience variables.

{TYPE}ADREXP refers to a datum of data type TYPE, located at address ADREXP.
@ is a binary operator for treating consecutive data objects
anywhere in memory as an array.  FOO@NUM gives an array whose first
element is FOO, whose second element is stored in the space following
where FOO is stored, etc.  FOO must be an expression whose value
resides in memory.

EXP may be preceded with /FMT, where FMT is a format letter
but no count or size letter (see "x" command).

(gdb) help x
Examine memory: x/FMT ADDRESS.
ADDRESS is an expression for the memory address to examine.
FMT is a repeat count followed by a format letter and a size letter.
Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),
  t(binary), f(float), a(address), i(instruction), c(char) and s(string),
  T(OSType), A(floating point values in hex).
Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).
The specified number of objects of the specified size are printed
according to the format.

Defaults for format and size letters are those previously used.
Default count is 1.  Default address is following last thing printed
with this command or "print".



요약하면

사용법: p/포맷 변수명

포맷: 
  x : 16진수
  d : 10진수
  u : unsigned 형식의(부호 없음) 10진수
  o : 8진수
  t : 2진수
  a : 주소
  c : ASCII 문자로 표시
  f : floating point
  s : 문자열로 표시
  T: OS type
  A: floating point 값을 16진수로 표시

포맷 참조시 조사한 x 명령어는 외부 메모리 내용을 보는 명령으로 포맷은

x/FMT 주소
FMT은 반복회수, 포맷, 출력 단위가 표시된다
출력단위는 b(byte), h(half word), w(word), g(giant byte: 8bytes)와 같다.

사용예:
(gdb) x/10db 0x100000e98
0x100000e98 <main+4>: 72 -115 61 -123 0 0 0 -24
0x100000ea0 <main+12>: 122 0
반응형