The Open Source Swiss Army Knife

/programmingToolBox/
/programmingToolBox/ + sub-categories
http://www.sirfsup.com/
web directory content
    
      

Not logged in
Chat Register Login
return to:  http:/www.sirfsup.com      /programmingToolBox 
Permalink: gdb.htm
Title: some useful gdb commands
article options : please login   |  print view

  1. compiling for debugging
  2. links
  3. examples
  4. assembly examples

links

http://www.linux-france.org/article/memo/node121.html)

linux programming unleashed

http://www.linux-france.org/article/memo/node119.html

examples

  1. ptype variable_name: shows the type of a variable
    • ptype S
      shows the structure definition, ptype does
      contrast to "whatis" which only reports the name of the structure without showing its definition
  2. whatis
    • whatis reports the name of the structure (then, do ptype on it)
    • whatis i
      type = int
  3. attache PID
  4. (gdb) x 0xffbef014
    PERMITS EXAMINIATION of memory 0xffbef014: 0x00000001
    (gdb)
    other examples: x/5x argv[0], ) x/6c argv[0], x/s argv[0]
  5. list (how to set and use)

    however, i am having a problem getting anything to list itself from the source file:

    [joe@www assembler]$ gdb exit_shellcode
    GNU gdb Red Hat Linux (6.0post-0.20040223.19rh)
    Copyright 2004 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type "show copying" to see the conditions.
    There is absolutely no warranty for GDB.  Type "show warranty" for details.
    This GDB was configured as "i386-redhat-linux-gnu"...
    (no debugging symbols found)...
    Using host libthread_db library "/lib/tls/libthread_db.so.1".
     
    (gdb) list
    No symbol table is loaded.  Use the "file" command.
    (gdb) list exit_shellcode
    No symbol table is loaded.  Use the "file" command.
    (gdb) file exit_shellcode
    Reading symbols from exit_shellcode...(no debugging symbols found)...done.
    (gdb) list
    No symbol table is loaded.  Use the "file" command.
    (gdb)
    

    I think that first, a "singlestep" mode must be entered ...see this link to the gdb docs. Actually, it probably needs be compiled with -g but it was actually an assembler file so to compile that i needed to use nasm -f elf exit_shellcode.txt and then ld -o exit_shellcode exit_shellcode.o. So, so much for compiling with debugging!

  6. set
    • set args -k3 caesar.cpp out.txt
    • set variable i = 10
  7. finish

    finish running the current function and print its return value

  8. return value

    stop running the current function and return value to the caller

  9. call
    • call name(args)
      call and execute the function named name with the arguments args
    • call index_to_the_moon(intary)
  10. print
    • print i
    • print ary[i]
    • print ary[i-1]
    • print $i-1
    • print ary@10 -- means print 10 values which begin at ary
    • print ary[71]@5 -- means print 5 values which begin at ary[71]
  11. break
    • (gdb) break NodePointer::show
      Breakpoint 1 at 0x993d0: file one.cpp, line 22.
      (gdb) condition 1 value_to_show==4
      (gdb)
      set the breakpoint at a function with break function_name
    • (gdb) b main
    • break aire_du_cercle if (r == 0)
    • break <filename:linenum>
    • break <linenum>
    • break <funcname>
    • break <filename:funcname>
    • break 25 if i=15
    • handle breakpoints:
    • clear, delete: clears breakpoints
    • delete: deletes all breakpoints and watchpoints
      disable,enable: resets breakpoints
    • watch
      sets observation points
    reads args from commandline only once gdb's been started?
  12. info
    • info program
    • info locals
      pertains to runningfunction's stack
    • info address i
      Symbol "i" is a local variable at frame offset -4.
    • info breakpoints
    • info frame
    • info registers
      shows what was in the registers at the time of the coredump, if run with gdb overflow core
    • info symbol 0x?????
      Breakpoint 1, main () at pointer_function.c:15
      15              return 0;
      (gdb) info symbol r
      No symbol matches r.
      (gdb) info symbol
      Argument required (address).
      (gdb) p &r
      $1 = (double *) 0x8049530
      (gdb) info symbol &r
      r in section .data
      (gdb)
      
  13. frames
    • frame 2
      after issuing a backtrace, lets you jump back to that function
    • up,down
      these two lets you go the previous frame (assume, frame is one per function, each function allocates its own frame on the stack
  14. reverse-search string
    finds occurrences of the string in the file
  15. shell <command>

보낸이: nobody@mnogosearch.org
받는이: general@mnogosearch.org
날짜: Today 19:37:34

Author: Alexey Zakhlestin
Email: indeyets@gmail.com

so we ran apache in single-process mode under GDB to get details fo mnogosearch 3.2.33 crash. here are those:



Program received signal SIGABRT, Aborted.

0x2825937b in kill () from /lib/libc.so.5

(gdb) bt

#0  0x2825937b in kill () from /lib/libc.so.5

#1  0x2824e422 in raise () from /lib/libc.so.5

#2  0x282c0c1b in abort () from /lib/libc.so.5

#3  0x282645b9 in ldexp () from /lib/libc.so.5

#4  0x282645fd in ldexp () from /lib/libc.so.5

#5  0x28265199 in ldexp () from /lib/libc.so.5

#6  0x28265743 in ldexp () from /lib/libc.so.5

#7  0x28265874 in free () from /lib/libc.so.5

#8  0x2896d87b in UdmSpellListListFree (L=0x861a928) at spell.c:201

#9  0x28981264 in UdmEnvFree (Env=0x861a000) at env.c:99

#10 0x283f79e0 in _free_udm_agent (rsrc=0x0) at /usr/home/skv/server/ok/php-5.0.4/ext/mnogosearch/php_mnogo.c:230

#11 0x285218f5 in list_entry_destructor (ptr=0x8630eec) at /usr/home/skv/server/php-5.0.4/Zend/zend_list.c:178

#12 0x2851fb5f in zend_hash_del_key_or_index (ht=0x285b14a8, arKey=0x0, nKeyLength=0, h=42, flag=1)

    at /usr/home/skv/server/php-5.0.4/Zend/zend_hash.c:490

#13 0x285216d4 in _zend_list_delete (id=42) at /usr/home/skv/server/php-5.0.4/Zend/zend_list.c:58

#14 0x283fb83a in zif_udm_free_agent (ht=1, return_value=0x87f78cc, this_ptr=0x0, return_value_used=0)

    at /usr/home/skv/server/ok/php-5.0.4/ext/mnogosearch/php_mnogo.c:2401

#15 0x285468bd in zend_do_fcall_common_helper (execute_data=0xbfbfb670, opline=0x8658698, op_array=0x860e70c)

    at /usr/home/skv/server/php-5.0.4/Zend/zend_execute.c:2727

#16 0x28546aeb in zend_do_fcall_handler (execute_data=0xbfbfb670, opline=0x8658698, op_array=0x860e70c)

    at /usr/home/skv/server/php-5.0.4/Zend/zend_execute.c:2859

#17 0x28537e73 in execute (op_array=0x860e70c) at /usr/home/skv/server/php-5.0.4/Zend/zend_execute.c:1406

#18 0x28546456 in zend_do_fcall_common_helper (execute_data=0xbfbfbcc0, opline=0x862fd70, op_array=0x860e60c)

    at /usr/home/skv/server/php-5.0.4/Zend/zend_execute.c:2756

#19 0x28537e73 in execute (op_array=0x860e60c) at /usr/home/skv/server/php-5.0.4/Zend/zend_execute.c:1406

#20 0x28546456 in zend_do_fcall_common_helper (execute_data=0xbfbfd120, opline=0x827aea8, op_array=0x824a40c)

    at /usr/home/skv/server/php-5.0.4/Zend/zend_execute.c:2756

#21 0x28537e73 in execute (op_array=0x824a40c) at /usr/home/skv/server/php-5.0.4/Zend/zend_execute.c:1406

#22 0x28546456 in zend_do_fcall_common_helper (execute_data=0xbfbfd2d0, opline=0x8255304, op_array=0x8132e0c)

    at /usr/home/skv/server/php-5.0.4/Zend/zend_execute.c:2756

#23 0x28537e73 in execute (op_array=0x8132e0c) at /usr/home/skv/server/php-5.0.4/Zend/zend_execute.c:1406

#24 0x2851aaf7 in zend_execute_scripts (type=8, retval=0x0, file_count=3)

    at /usr/home/skv/server/php-5.0.4/Zend/zend.c:1069

#25 0x284ea1b4 in php_execute_script (primary_file=0xbfbfe940) at /usr/home/skv/server/php-5.0.4/main/main.c:1632

#26 0x2854e4ae in php_handler (r=0x8234528) at /usr/home/skv/server/php-5.0.4/sapi/apache2handler/sapi_apache2.c:555

#27 0x080822ae in ap_run_handler (r=0x8234528) at config.c:152

#28 0x08082679 in ap_invoke_handler (r=0x8234528) at config.c:364

#29 0x0806a8e5 in ap_internal_redirect (new_uri=0x0, r=0x8a1d) at http_request.c:465

#30 0x0806ac12 in ap_process_request (r=0x822f050) at http_request.c:262

#31 0x0806663d in ap_process_http_connection (c=0x8229128) at http_core.c:251

#32 0x0808bac6 in ap_run_process_connection (c=0x8229128) at connection.c:43

#33 0x08080ac5 in child_main (child_num_arg=0) at prefork.c:610

#34 0x08080cb9 in make_child (s=0x80c3cd0, slot=0) at prefork.c:650

#35 0x08080d80 in startup_children (number_to_start=50) at prefork.c:722

#36 0x08081403 in ap_mpm_run (_pconf=0xbfbfec10, plog=0x80f7018, s=0xbfbfec18) at prefork.c:941

#37 0x0808659f in main (argc=2, argv=0xbfbfed04) at main.c:618

(gdb) frame 8

#8  0x2896d87b in UdmSpellListListFree (L=0x861a928) at spell.c:201

201         UdmFree(L->Item);

(gdb) list

196     {

197       size_t i;

198       for (i=0 ; i < L->nitems; i++)

199         stUdmSpellListFree(&L->Item[i]);

200       if (L->Item)

201         UdmFree(L->Item);

202     }

203

204     int

205     UdmSpellListListAdd(UDM_SPELLLISTLIST *L,

(gdb) print L->Item

$1 = (UDM_SPELLLIST *) 0x864d000

(gdb) print L

$2 = (UDM_SPELLLISTLIST *) 0x861a928

(gdb) print *L

$4 = {nitems = 2, mitems = 16, nspell = 0, Item = 0x864d000}

(gdb) print *(L->Item)

$5 = {lang = "ru", '\0' <repeats 29 times>, cset = "windows-1251", '\0' <repeats 19 times>,

  fname = "/usr/local/share/ispell/russian.dict", '\0' <repeats 91 times>, cs = 0x289d6320, fbody = 0x0,

  nitems = 89038, mitems = 98304, Item = 0x0}

assembly examples

the stack in RAM

see The Shellcoder's handbook.

x/2 address
(gdb) x/s 0x80499a8
0x80499a8: 'A' <repeats 94 times>, "\n"
disass main
dumps assembler code for function main

Leave a Reply
Your Name:     anonymous
Your Email:
Website:  
Comments:

The author will be notified of your reply.
return to top