LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1054|回复: 4

gdb出问题鸟

[复制链接]
发表于 2005-11-22 12:54:49 | 显示全部楼层 |阅读模式
不知道什么时候开始,我的gdb设置断点后运行总是报错,像这样:
  1. gdb> list
  2. 1       #include<stdio.h>
  3. 2
  4. 3       int main()
  5. 4       {
  6. 5               int i;
  7. 6               for(i=0;i<10;i++)
  8. 7               {
  9. 8                       printf("%d",i);
  10. 9               }
  11. 10              return 0;
  12. gdb> b 6
  13. Breakpoint 1 at 0x8048394: file a.c, line 6.
  14. gdb> r
  15. Error while running hook_stop:
  16. Invalid type combination in ordering comparison.

  17. Breakpoint 1, main () at a.c:6
  18. 6               for(i=0;i<10;i++)
  19. gdb> s
  20. Error while running hook_stop:
  21. Invalid type combination in ordering comparison.
  22. 8                       printf("%d",i);
  23. gdb>
  24. Error while running hook_stop:
  25. Invalid type combination in ordering comparison.
  26. 6               for(i=0;i<10;i++)
  27. gdb>
  28. Error while running hook_stop:
  29. Invalid type combination in ordering comparison.
  30. 8                       printf("%d",i);
  31. gdb>
复制代码
这个是咋回事哩?
发表于 2005-11-23 01:38:28 | 显示全部楼层
估计你的gdb没有安装好,再安装一次吧
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-11-23 22:13:11 | 显示全部楼层
Post by kj501
估计你的gdb没有安装好,再安装一次吧

小弟装了很多遍了。。。
回复 支持 反对

使用道具 举报

发表于 2006-5-6 02:23:59 | 显示全部楼层
我也遇到这个问题鸟。

普通用户会出现这个问题,换成root就可以了。怎么解决呢?难不成我每次调试都要换成root?
回复 支持 反对

使用道具 举报

发表于 2006-5-6 11:15:04 | 显示全部楼层
搞定了。我发现随便新建一个用户动能用gdb,就是ifree这个帐号用不了。于是就到主目录下去看看。发现一个不知道哪儿来的文件:.gdbinit
删掉后就OK了。不知道为什么。

附上该文件,大家看看是什么问题:
  1. # INSTRUCTIONS: save as ~/.gdbinit
  2. #
  3. # DESCRIPTION: A user-friendly gdb configuration file.
  4. #
  5. # REVISION : 6.1-gentoo
  6. #
  7. # CONTRIBUTORS: mammon_, elaine, pusillus, mong
  8. #
  9. # FEEDBACK: http://board.anticrack.de/viewforum.php?f=35
  10. # SOURCE:   http://www.eccentrix.com/members/mammon/gdb_init.txt
  11. # NOTES: 'help user' in gdb will list the commands/descriptions in this file
  12. #        'context on' now enables auto-display of context screen
  13. #
  14. # CHANGELOG:
  15. #        Version 6.1-gentoo
  16. #         made gas the default. some content censored to be *cough*
  17. #         politically correct. -solar
  18. #        Version 6.1
  19. #        fixed filename in step_to_call so it points to /dev/null
  20. #        changed location of logfiles from /tmp  to ~
  21. #        Version 6
  22. #         added print_insn_type, get_insn_type, context-on, context-off commands
  23. #         added trace_calls, trace_run, step_to_call commands
  24. #         changed hook-stop so it checks $SHOW_CONTEXT variable
  25. #        Version 5
  26. #         added bpm, dump_bin, dump_hex, bp_alloc commands
  27. #        added 'assemble' by elaine, 'gas_asm' by mong
  28. #         added Tip Topics for aspiring *cough* ;)
  29. #         Version 4
  30. #         added eflags-changing insns by pusillus
  31. #         added bp, nop, null, and int3 patch commands, also hook-stop
  32. #        Version 3
  33. #         incorporated elaine's if/else goodness into the hex/ascii dump
  34. #        Version 2
  35. #         radix bugfix by elaine
  36. # TODO:
  37. #        * add global vars to allow user to control stack,data,code win sizes
  38. #        * add dump, append, set write, etc commands
  39. #        * more tips!
  40. # ______________breakpoint aliases_____________
  41. define bpl
  42. info breakpoints
  43. end
  44. document bpl
  45. List breakpoints
  46. end
  47. define bp
  48. set $SHOW_CONTEXT = 1
  49. break * $arg0
  50. end
  51. document bp
  52. Set a breakpoint on address
  53. Usage: bp addr
  54. end
  55. define bpc
  56. clear $arg0
  57. end
  58. document bpc
  59. Clear breakpoint at function/address
  60. Usage: bpc addr
  61. end
  62. define bpe
  63. enable $arg0
  64. end
  65. document bpe
  66. Enable breakpoint #
  67. Usage: bpe num
  68. end
  69. define bpd
  70. disable $arg0
  71. end
  72. document bpd
  73. Disable breakpoint #
  74. Usage: bpd num
  75. end
  76. define bpt
  77. set $SHOW_CONTEXT = 1
  78. tbreak $arg0
  79. end
  80. document bpt
  81. Set a temporary breakpoint on address
  82. Usage: bpt addr
  83. end
  84. define bpm
  85. set $SHOW_CONTEXT = 1
  86. awatch $arg0
  87. end
  88. document bpm
  89. Set a read/write breakpoint on address
  90. Usage: bpm addr
  91. end
  92. # ______________process information____________
  93. define argv
  94. show args
  95. end
  96. document argv
  97. Print program arguments
  98. end
  99. define stack
  100. info stack
  101. end
  102. document stack
  103. Print call stack
  104. end
  105. define frame
  106. info frame
  107. info args
  108. info locals
  109. end
  110. document frame
  111. Print stack frame
  112. end
  113. define flags
  114. if (($eflags >> 0xB) & 1 )
  115.   printf "O "
  116. else
  117.   printf "o "
  118. end
  119. if (($eflags >> 0xA) & 1 )
  120.   printf "D "
  121. else
  122.   printf "d "
  123. end
  124. if (($eflags >> 9) & 1 )
  125.   printf "I "
  126. else
  127.   printf "i "
  128. end
  129. if (($eflags >> 8) & 1 )
  130.   printf "T "
  131. else
  132.   printf "t "
  133. end
  134. if (($eflags >> 7) & 1 )
  135.   printf "S "
  136. else
  137.   printf "s "
  138. end
  139. if (($eflags >> 6) & 1 )
  140.   printf "Z "
  141. else
  142.   printf "z "
  143. end
  144. if (($eflags >> 4) & 1 )
  145.   printf "A "
  146. else
  147.   printf "a "
  148. end
  149. if (($eflags >> 2) & 1 )
  150.   printf "P "
  151. else
  152.   printf "p "
  153. end
  154. if ($eflags & 1)
  155.   printf "C "
  156. else
  157.   printf "c "
  158. end
  159. printf "\n"
  160. end
  161. document flags
  162. Print flags register
  163. end
  164. define eflags
  165. printf "     OF <%d>  DF <%d>  IF <%d>  TF <%d>",\
  166.         (($eflags >> 0xB) & 1 ), (($eflags >> 0xA) & 1 ), \
  167.         (($eflags >> 9) & 1 ), (($eflags >> 8) & 1 )
  168. printf "  SF <%d>  ZF <%d>  AF <%d>  PF <%d>  CF <%d>\n",\
  169.         (($eflags >> 7) & 1 ), (($eflags >> 6) & 1 ),\
  170.         (($eflags >> 4) & 1 ), (($eflags >> 2) & 1 ), ($eflags & 1)
  171. printf "     ID <%d>  VIP <%d> VIF <%d> AC <%d>",\
  172.         (($eflags >> 0x15) & 1 ), (($eflags >> 0x14) & 1 ), \
  173.         (($eflags >> 0x13) & 1 ), (($eflags >> 0x12) & 1 )
  174. printf "  VM <%d>  RF <%d>  NT <%d>  IOPL <%d>\n",\
  175.         (($eflags >> 0x11) & 1 ), (($eflags >> 0x10) & 1 ),\
  176.         (($eflags >> 0xE) & 1 ), (($eflags >> 0xC) & 3 )
  177. end
  178. document eflags
  179. Print entire eflags register
  180. end
  181. define reg
  182. printf "     eax:%08X ebx:%08X  ecx:%08X ",  $eax, $ebx, $ecx
  183. printf " edx:%08X     eflags:%08X\n",  $edx, $eflags
  184. printf "     esi:%08X edi:%08X  esp:%08X ",  $esi, $edi, $esp
  185. printf " ebp:%08X     eip:%08X\n", $ebp, $eip
  186. printf "     cs:%04X  ds:%04X  es:%04X", $cs, $ds, $es
  187. printf "  fs:%04X  gs:%04X  ss:%04X    ", $fs, $gs, $ss
  188. flags
  189. end
  190. document reg
  191. Print CPU registers
  192. end
  193. define func
  194. info functions
  195. end
  196. document func
  197. Print functions in target
  198. end
  199. define var
  200. info variables
  201. end
  202. document var
  203. Print variables (symbols) in target
  204. end
  205. define lib
  206. info sharedlibrary
  207. end
  208. document lib
  209. Print shared libraries linked to target
  210. end
  211. define sig
  212. info signals
  213. end
  214. document sig
  215. Print signal actions for target
  216. end
  217. define thread
  218. info threads
  219. end
  220. document thread
  221. Print threads in target
  222. end
  223. define u
  224. info udot
  225. end
  226. document u
  227. Print kernel 'user' struct for target
  228. end
  229. define dis
  230. disassemble $arg0
  231. end
  232. document dis
  233. Disassemble address
  234. Usage: dis addr
  235. end
  236. # ________________hex/ascii dump an address______________
  237. define ascii_char
  238. # thanks elaine :)
  239. set $_c=*(unsigned char *)($arg0)
  240. if ( $_c < 0x20 || $_c > 0x7E )
  241.   printf "."
  242. else
  243.   printf "%c", $_c
  244. end
  245. end
  246. document ascii_char
  247. Print the ASCII value of arg0 or '.' if value is unprintable
  248. end
  249. define hex_quad
  250. printf "%02X %02X %02X %02X  %02X %02X %02X %02X",                          \
  251.                 *(unsigned char*)($arg0), *(unsigned char*)($arg0 + 1),      \
  252.                 *(unsigned char*)($arg0 + 2), *(unsigned char*)($arg0 + 3),  \
  253.                 *(unsigned char*)($arg0 + 4), *(unsigned char*)($arg0 + 5),  \
  254.                 *(unsigned char*)($arg0 + 6), *(unsigned char*)($arg0 + 7)
  255. end
  256. document hex_quad
  257. Print eight hexadecimal bytes starting at arg0
  258. end
  259. define hexdump
  260. printf "%08X : ", $arg0
  261. hex_quad $arg0
  262. printf " - "
  263. hex_quad ($arg0+8)
  264. printf " "
  265. ascii_char ($arg0)
  266. ascii_char ($arg0+1)
  267. ascii_char ($arg0+2)
  268. ascii_char ($arg0+3)
  269. ascii_char ($arg0+4)
  270. ascii_char ($arg0+5)
  271. ascii_char ($arg0+6)
  272. ascii_char ($arg0+7)
  273. ascii_char ($arg0+8)
  274. ascii_char ($arg0+9)
  275. ascii_char ($arg0+0xA)
  276. ascii_char ($arg0+0xB)
  277. ascii_char ($arg0+0xC)
  278. ascii_char ($arg0+0xD)
  279. ascii_char ($arg0+0xE)
  280. ascii_char ($arg0+0xF)
  281. printf "\n"
  282. end
  283. document hexdump
  284. Display a 16-byte hex/ASCII dump of arg0
  285. end
  286. # ________________data window__________________
  287. define ddump
  288. printf "[%04X:%08X]------------------------", $ds, $data_addr
  289. printf "---------------------------------[ data]\n"
  290. set $_count=0
  291. while ( $_count < $arg0 )
  292.   set $_i=($_count*0x10)
  293.   hexdump ($data_addr+$_i)
  294.   set $_count++
  295. end
  296. end
  297. document ddump
  298. Display $arg0 lines of hexdump for address $data_addr
  299. end
  300. define dd
  301. if ( ($arg0 & 0x40000000) || ($arg0 & 0x08000000) || ($arg0 & 0xBF000000) )
  302.   set $data_addr=$arg0
  303.   ddump 0x10
  304. else
  305.   printf "Invalid address: %08X\n", $arg0
  306. end
  307. end
  308. document dd
  309. Display 16 lines of a hex dump for $arg0
  310. end
  311. define datawin
  312. if ( ($esi & 0x40000000) || ($esi & 0x08000000) || ($esi & 0xBF000000) )
  313.   set $data_addr=$esi
  314. else
  315.   if ( ($edi & 0x40000000) || ($edi & 0x08000000) || ($edi & 0xBF000000) )
  316.    set $data_addr=$edi
  317.   else
  318.    if ( ($eax & 0x40000000) || ($eax & 0x08000000) || \
  319.         ($eax & 0xBF000000) )
  320.     set $data_addr=$eax
  321.    else
  322.     set $data_addr=$esp
  323.    end
  324.   end
  325. end
  326. ddump 2
  327. end
  328. document datawin
  329. Display esi, edi, eax, or esp in data window
  330. end
  331. # ________________process context______________
  332. define context
  333. printf "_______________________________________"
  334. printf "________________________________________\n"
  335. reg
  336. printf "[%04X:%08X]------------------------", $ss, $esp
  337. printf "---------------------------------[stack]\n"
  338. hexdump $sp+0x30
  339. hexdump $sp+0x20
  340. hexdump $sp+0x10
  341. hexdump $sp
  342. datawin
  343. printf "[%04X:%08X]------------------------", $cs, $eip
  344. printf "---------------------------------[ code]\n"
  345. x /6i $pc
  346. printf "---------------------------------------"
  347. printf "---------------------------------------\n"
  348. end
  349. document context
  350. Print regs, stack, ds:esi, and disassemble cs:eip
  351. end
  352. define context-on
  353. set $SHOW_CONTEXT = 1
  354. end
  355. document context-on
  356. Enable display of context on every program stop
  357. end
  358. define context-off
  359. set $SHOW_CONTEXT = 1
  360. end
  361. document context-on
  362. Disable display of context on every program stop
  363. end
  364. # ________________process control______________
  365. define n
  366. ni
  367. end
  368. document n
  369. Step one instruction
  370. end
  371. define go
  372. stepi $arg0
  373. end
  374. document go
  375. Step # instructions
  376. end
  377. define pret
  378. finish
  379. end
  380. document pret
  381. Step out of current call
  382. end
  383. define init
  384. set $SHOW_CONTEXT = 1
  385. set $SHOW_NEST_INSN=0
  386. tbreak _init
  387. r
  388. end
  389. document init
  390. Run program; break on _init()
  391. end
  392. define start
  393. set $SHOW_CONTEXT = 1
  394. set $SHOW_NEST_INSN=0
  395. tbreak _start
  396. r
  397. end
  398. document start
  399. Run program; break on _start()
  400. end
  401. define sstart
  402. set $SHOW_CONTEXT = 1
  403. set $SHOW_NEST_INSN=0
  404. tbreak __libc_start_main
  405. r
  406. end
  407. document sstart
  408. Run program; break on __libc_start_main(). Useful for stripped executables.
  409. end
  410. define main
  411. set $SHOW_CONTEXT = 1
  412. set $SHOW_NEST_INSN=0
  413. tbreak main
  414. r
  415. end
  416. document main
  417. Run program; break on main()
  418. end
  419. # ________________eflags commands_______________
  420. define cfc
  421. if ($eflags & 1)
  422.   set $eflags = $eflags&~1
  423. else
  424.   set $eflags = $eflags|1
  425. end
  426. end
  427. document cfc
  428. change Carry Flag
  429. end
  430. define cfp
  431. if (($eflags >> 2) & 1 )
  432.   set $eflags = $eflags&~0x4
  433. else
  434.   set $eflags = $eflags|0x4
  435. end
  436. end
  437. document cfp
  438. change Carry Flag
  439. end
  440. define cfa
  441. if (($eflags >> 4) & 1 )
  442.   set $eflags = $eflags&~0x10
  443. else
  444.   set $eflags = $eflags|0x10
  445. end
  446. end
  447. document cfa
  448. change Auxiliary Carry Flag
  449. end
  450. define cfz
  451. if (($eflags >> 6) & 1 )
  452.   set $eflags = $eflags&~0x40
  453. else
  454.   set $eflags = $eflags|0x40
  455. end
  456. end
  457. document cfz
  458. change Zero Flag
  459. end
  460. define cfs
  461. if (($eflags >> 7) & 1 )
  462.   set $eflags = $eflags&~0x80
  463. else
  464.   set $eflags = $eflags|0x80
  465. end
  466. end
  467. document cfs
  468. change Sign Flag
  469. end
  470. define cft
  471. if (($eflags >>8) & 1 )
  472.   set $eflags = $eflags&100
  473. else
  474.   set $eflags = $eflags|100
  475. end
  476. end
  477. document cft
  478. change Trap Flag
  479. end
  480. define cfi
  481. if (($eflags >> 9) & 1 )
  482.   set $eflags = $eflags&~0x200
  483. else
  484.   set $eflags = $eflags|0x200
  485. end
  486. end
  487. document cfi
  488. change Interrupt Flag
  489. end
  490. define cfd
  491. if (($eflags >>0xA ) & 1 )
  492.   set $eflags = $eflags&~0x400
  493. else
  494.   set $eflags = $eflags|0x400
  495. end
  496. end
  497. document cfd
  498. change Direction Flag
  499. end
  500. define cfo
  501. if (($eflags >> 0xB) & 1 )
  502.   set $eflags = $eflags&~0x800
  503. else
  504.   set $eflags = $eflags|0x800
  505. end
  506. end
  507. document cfo
  508. change Overflow Flag
  509. end
  510. # --------------------patch---------------------
  511. define nop
  512. set * (unsigned char *) $arg0 = 0x90
  513. end
  514. document nop
  515. Patch byte at address arg0 to a NOP insn
  516. Usage: nop addr
  517. end
  518. define null
  519. set * (unsigned char *) $arg0 = 0
  520. end
  521. document null
  522. Patch byte at address arg0 to  NULL
  523. Usage: null addr
  524. end
  525. define int3
  526. set * (unsigned char *) $arg0 = 0xCC
  527. end
  528. document int3
  529. Patch byte at address arg0 to an INT3 insn
  530. Usage: int3 addr
  531. end
  532. # --------------------cflow---------------------
  533. define print_insn_type
  534. if ($arg0 == 0)
  535.   printf "UNKNOWN";
  536. end
  537. if ($arg0 == 1)
  538.   printf "JMP";
  539. end
  540. if ($arg0 == 2)
  541.   printf "JCC";
  542. end
  543. if ($arg0 == 3)
  544.   printf "CALL";
  545. end
  546. if ($arg0 == 4)
  547.   printf "RET";
  548. end
  549. if ($arg0 == 5)
  550.   printf "INT";
  551. end
  552. end
  553. document print_insn_type
  554. This prints the human-readable mnemonic for the instruction typed passed as
  555. a parameter (usually $INSN_TYPE).
  556. end
  557. define get_insn_type
  558. set $INSN_TYPE = 0
  559. set $_byte1=*(unsigned char *)$arg0
  560. if ($_byte1 == 0x9A || $_byte1 == 0xE8 )
  561.   # "call"
  562.   set $INSN_TYPE=3
  563. end
  564. if ($_byte1 >= 0xE9 && $_byte1 <= 0xEB)
  565.   # "jmp"
  566.   set $INSN_TYPE=1
  567. end
  568. if ($_byte1 >= 0x70 && $_byte1 <= 0x7F)
  569.   # "jcc"
  570.   set $INSN_TYPE=2
  571. end
  572. if ($_byte1 >= 0xE0 && $_byte1 <= 0xE3 )
  573.   # "jcc"
  574.   set $INSN_TYPE=2
  575. end
  576. if ($_byte1 == 0xC2 || $_byte1 == 0xC3 || $_byte1 == 0xCA || $_byte1 == 0xCB || $_byte1 == 0xCF)
  577.   # "ret"
  578.   set $INSN_TYPE=4               
  579. end
  580. if ($_byte1 >= 0xCC && $_byte1 <= 0xCE)
  581.   # "int"
  582.   set $INSN_TYPE=5
  583. end
  584. if ($_byte1 == 0x0F )
  585.   # two-byte opcode
  586.   set $_byte2=*(unsigned char *)($arg0 +1)
  587.   if ($_byte2 >= 0x80 && $_byte2 <= 0x8F)
  588.    # "jcc"
  589.    set $INSN_TYPE=2
  590.   end
  591. end
  592. if ($_byte1 == 0xFF )       
  593.   # opcode extension
  594.   set $_byte2=*(unsigned char *)($arg0 +1)
  595.   set $_opext=($_byte2 & 0x38)
  596.   if ($_opext == 0x10 || $_opext == 0x18)
  597.    # "call"
  598.    set $INSN_TYPE=3
  599.   end
  600.   if ($_opext == 0x20 || $_opext == 0x28)
  601.    # "jmp"
  602.    set $INSN_TYPE=1
  603.   end
  604. end
  605. end
  606. document get_insn_type
  607. This takes an address as a parameter and sets the global $INSN_TYPE variable
  608. to 0, 1, 2, 3, 4, 5 if the instruction at the address is unknown, a jump,
  609. a conditional jump, a call, a return, or an interrupt.
  610. end
  611. define step_to_call
  612. set $_saved_ctx = $SHOW_CONTEXT
  613. set $SHOW_CONTEXT = 0
  614. set $SHOW_NEST_INSN=0
  615. set logging file /dev/null
  616. set logging on
  617. set logging redirect on
  618. set $_cont = 1
  619. while ( $_cont > 0 )
  620.   stepi
  621.   get_insn_type $pc
  622.   if ($INSN_TYPE == 3)
  623.    set $_cont = 0
  624.   end
  625. end
  626. if ( $_saved_ctx > 0 )
  627.   context
  628. else
  629.   x /i $pc
  630. end
  631. set $SHOW_CONTEXT = 1
  632. set $SHOW_NEST_INSN=0
  633. set logging redirect off
  634. set logging off
  635. set logging file gdb.txt
  636. end
  637. document step_to_call
  638. This single steps until it encounters a call instruction; it stops before
  639. the call is taken.
  640. end
  641. define trace_calls
  642. set $SHOW_CONTEXT = 0
  643. set $SHOW_NEST_INSN=0
  644. set $_nest = 1
  645. set listsize 0
  646. set logging overwrite on
  647. set logging file ~/gdb_trace_calls.txt
  648. set logging on
  649. set logging redirect on
  650. while ( $_nest > 0 )
  651.   get_insn_type $pc
  652.   # handle nesting
  653.   if ($INSN_TYPE == 3)
  654.    set $_nest = $_nest + 1
  655.   else
  656.    if ($INSN_TYPE == 4)
  657.     set $_nest = $_nest - 1
  658.    end
  659.   end
  660.   # if a call, print it
  661.   if ($INSN_TYPE == 3)
  662.    set $x = $_nest
  663.    while ( $x > 0 )
  664.     printf "\t"
  665.     set $x = $x - 1
  666.    end
  667.    x /i $pc
  668.   end
  669.   #set logging file /dev/null
  670.   stepi
  671.   #set logging file ~/gdb_trace_calls.txt
  672. end
  673. set $SHOW_CONTEXT = 1
  674. set $SHOW_NEST_INSN=0
  675. set logging redirect off
  676. set logging off
  677. set logging file gdb.txt
  678. # clean up trace file
  679. shell  grep -v ' at ' ~/gdb_trace_calls.txt > ~/gdb_trace_calls.1
  680. shell  grep -v ' in ' ~/gdb_trace_calls.1 > ~/gdb_trace_calls.txt
  681. end
  682. document trace_calls
  683. Creates a runtime trace of the calls made target in ~/gdb_trace_calls.txt.
  684. Note that this is very slow because gdb "set redirect on" does not work!
  685. end
  686. define trace_run
  687. set $SHOW_CONTEXT = 0
  688. set $SHOW_NEST_INSN=1
  689. set logging overwrite on
  690. set logging file ~/gdb_trace_run.txt
  691. set logging on
  692. set logging redirect on
  693. set $_nest = 1
  694. while ( $_nest > 0 )
  695.   get_insn_type $pc
  696.   # jmp, jcc, or cll
  697.   if ($INSN_TYPE == 3)
  698.    set $_nest = $_nest + 1
  699.   else
  700.    # ret
  701.    if ($INSN_TYPE == 4)
  702.     set $_nest = $_nest - 1
  703.    end
  704.   end
  705.   stepi
  706. end
  707. set $SHOW_CONTEXT = 1
  708. set $SHOW_NEST_INSN=0
  709. set logging file gdb.txt
  710. set logging redirect off
  711. set logging off
  712. # clean up trace file
  713. shell  grep -v ' at ' ~/gdb_trace_run.txt > ~/gdb_trace_run.1
  714. shell  grep -v ' in ' ~/gdb_trace_run.1 > ~/gdb_trace_run.txt
  715. end
  716. document trace_run
  717. Creates a runtime trace of the target in ~/gdb_trace_run.txt. Note
  718. that this is very slow because gdb "set redirect on" does not work!
  719. end
  720. # _____________________misc_____________________
  721. # this makes 'context' be called at every BP/step
  722. define hook-stop
  723. if ( $SHOW_CONTEXT > 0 )
  724.   context
  725. end
  726. if ( $SHOW_NEST_INSN > 0 )
  727.   set $x = $_nest
  728.   while ($x > 0 )
  729.    printf "\t"
  730.    set $x = $x - 1
  731.   end
  732. end
  733. end
  734. define nasm_assemble
  735. printf "Hit Ctrl-D to start, type code to assemble, hit Ctrl-D when done.\n"
  736. printf "It is recommended to start with\n"
  737. printf "\tBITS 32\n"
  738. printf "Note that this command uses NASM (Intel syntax) to assemble.\n"
  739. shell nasm -f bin -o /dev/stdout /dev/stdin | od -v -t x1 -w16 -A n
  740. end
  741. document nasm_assemble
  742. Assemble Intel x86 instructions to binary opcodes. Uses nasm.
  743. Usage: nasm_assemble
  744. end
  745. define assemble
  746. printf "Type code to assemble, hit Ctrl-D until results appear :)\n"
  747. printf "Note that this command uses GAS (AT&T syntax) to assemble.\n"
  748. shell as -o ~/__gdb_tmp.bin
  749. shell objdump -d -j .text --adjust-vma=$arg0 ~/__gdb_tmp.bin
  750. shell rm ~/__gdb_tmp.bin
  751. end
  752. document assemble
  753. Assemble Intel x86 instructions to binary opcodes using gas and objdump
  754. Usage: assemble address
  755. end
  756. # !scary bp_alloc macro!
  757. # The idea behind this macro is to break on the following code:
  758. #        0x4008e0aa <malloc+6>:  sub    $0xc,%esp
  759. #        0x4008e0ad <malloc+9>:  call   0x4008e0b2 <malloc+14>
  760. #        0x4008e0b2 <malloc+14>: pop    %ebx
  761. #        0x4008e0b3 <malloc+15>: add    $0xa3f6e,%ebx
  762. # At 0x4008e0b3, %ebx contains the address that has just been allocated
  763. # The bp_alloc macro generates this breakpoint and *should* work for
  764. # the forseeable future ... but if it breaks, set a breakpoint on
  765. # __libc_malloc and look for where where the return value gets popped.
  766. define bp_alloc
  767. tbreak *(*__libc_malloc + F) if $ebx == $arg0
  768. end
  769. document bp_alloc
  770. This sets a temporary breakpoint on the allocation of $arg0.
  771. It works by setting a breakpoint on a specific address in __libc_malloc().
  772. USE WITH CAUTION -- it is extremely platform dependent.
  773. Usage: bp_alloc addr
  774. end
  775. define dump_hexfile
  776. dump ihex memory $arg0 $arg1 $arg2
  777. end
  778. document dump_hexfile
  779. Write a range of memory to a file in Intel ihex (hexdump) format.
  780. Usage:        dump_hexfile filename start_addr end_addr
  781. end
  782. define dump_binfile
  783. dump memory $arg0 $arg1 $arg2
  784. end
  785. document dump_binfile
  786. Write a range of memory to a binary file.
  787. Usage:        dump_binfile filename start_addr end_addr
  788. end
  789.        
  790. # _________________tips_________________
  791. # The 'tips' command is used to provide tutorial-like info to the user
  792. define tips
  793.         printf "Tip Topic Commands:\n"
  794.         printf "\ttip_display : Automatically display values on each break\n"
  795.         printf "\ttip_patch   : Patching binaries\n"
  796.         printf "\ttip_strip   : Dealing with stripped binaries\n"
  797.         printf "\ttip_syntax  : ATT vs Intel syntax\n"
  798. end
  799. document tips
  800. Provide a list of tips from users on various topics.
  801. end
  802. define tip_patch
  803.         printf "\n"
  804.         printf "                   PATCHING MEMORY\n"
  805.         printf "Any address can be patched using the 'set' command:\n"
  806.         printf "\t`set ADDR = VALUE` \te.g. `set *0x8049D6E = 0x90`\n"
  807.         printf "\n"
  808.         printf "                 PATCHING BINARY FILES\n"
  809.         printf "Use `set write` in order to patch the target executable\n"
  810.         printf "directly, instead of just patching memory.\n"
  811.         printf "\t`set write on` \t`set write off`\n"
  812.         printf "Note that this means any patches to the code or data segments\n"
  813.         printf "will be written to the executable file. When either of these\n"
  814.         printf "commands has been issued, the file must be reloaded.\n"
  815.         printf "\n"
  816. end
  817. document tip_patch
  818. Tips on patching memory and binary files
  819. end
  820. define tip_strip
  821.         printf "\n"
  822.         printf "             STOPPING BINARIES AT ENTRY POINT\n"
  823.         printf "Stripped binaries have no symbols, and are therefore tough to\n"
  824.         printf "start automatically. To debug a stripped binary, use\n"
  825.         printf "\tinfo file\n"
  826.         printf "to get the entry point of the file. The first few lines of\n"
  827.         printf "output will look like this:\n"
  828.         printf "\tSymbols from '/tmp/a.out'\n"
  829.         printf "\tLocal exec file:\n"
  830.         printf "\t        `/tmp/a.out', file type elf32-i386.\n"
  831.         printf "\t        Entry point: 0x80482e0\n"
  832.         printf "Use this entry point to set an entry point:\n"
  833.         printf "\t`tbreak *0x80482e0`\n"
  834.         printf "The breakpoint will delete itself after the program stops as\n"
  835.         printf "the entry point.\n"
  836.         printf "\n"
  837. end
  838. document tip_strip
  839. Tips on dealing with stripped binaries
  840. end
  841. define tip_syntax
  842.         printf "\n"
  843.         printf "\t    INTEL SYNTAX                        AT&T SYNTAX\n"
  844.         printf "\tmnemonic dest, src, imm            mnemonic src, dest, imm\n"
  845.         printf "\t[base+index*scale+disp]            disp(base, index, scale)\n"
  846.         printf "\tregister:      eax                 register:      %%eax\n"
  847.         printf "\timmediate:     0xFF                immediate:     $0xFF\n"
  848.         printf "\tdereference:   [addr]              dereference:   addr(,1)\n"
  849.         printf "\tabsolute addr: addr                absolute addr: *addr\n"
  850.         printf "\tbyte insn:     mov byte ptr        byte insn:     movb\n"
  851.         printf "\tword insn:     mov word ptr        word insn:     movw\n"
  852.         printf "\tdword insn:    mov dword ptr       dword insn:    movd\n"
  853.         printf "\tfar call:      call far            far call:      lcall\n"
  854.         printf "\tfar jump:      jmp far             far jump:      ljmp\n"
  855.         printf "\n"
  856.         printf "Note that order of operands in reversed, and that AT&T syntax\n"
  857.         printf "requires that all instructions referencing memory operands \n"
  858.         printf "use an operand size suffix (b, w, d, q).\n"
  859.         printf "\n"
  860. end
  861. document tip_syntax
  862. Summary of Intel and AT&T syntax differences
  863. end
  864. define tip_display
  865. printf "\n"
  866. printf "Any expression can be set to automatically be displayed every time\n"
  867. printf "the target stops. The commands for this are:\n"
  868. printf "\t`display expr'     : automatically display expression 'expr'\n"
  869. printf "\t`display'          : show all displayed expressions\n"
  870. printf "\t`undisplay num'    : turn off autodisplay for expression # 'num'\n"
  871. printf "Examples:\n"
  872. printf "\t`display/x *(int *)$esp`      : print top of stack\n"
  873. printf "\t`display/x *(int *)($ebp+8)`  : print first parameter\n"
  874. printf "\t`display (char *)$esi`        : print source string\n"
  875. printf "\t`display (char *)$edi`        : print destination string\n"
  876. printf "\n"
  877. end
  878. document tip_display
  879. Tips on automatically displaying values when a program stops.
  880. end
  881. # __________________gdb options_________________
  882. set confirm off
  883. set verbose off
  884. set prompt gdb>
  885. set output-radix 0x10
  886. set input-radix 0x10
  887. # These make gdb never pause in its output
  888. set height 0
  889. set width 0
  890. # why do these not work???
  891. set $SHOW_CONTEXT = 1
  892. set $SHOW_NEST_INSN=0
  893. #EOF
复制代码
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表