Difference between revisions of "Rossym.gdb"

From ReactOS Wiki
Jump to: navigation, search
(rossym.gdb: Added print-modules, a slightly modified load-all-modules that just prints the current addresses.)
(rossym.gdb: Make load-module-nostrip tolerant of modules built without nostrip, and hopefully even modules not found in output-i386)
Line 21: Line 21:
 
         end_log
 
         end_log
 
         shell sed -e 's/\..*$//g' < sym.tmp > modname_stripped.txt
 
         shell sed -e 's/\..*$//g' < sym.tmp > modname_stripped.txt
         shell find output-i386 -name `head -n 1 modname_stripped.txt`.nostrip.\* > found_mod.txt
+
         shell find output-i386 -iname `head -n 1 modname_stripped.txt `'.nostrip.*' > found_mod.txt
 +
        shell test -s found_mod.txt || find output-i386 -iname `head -n 1 modname_stripped.txt `.'???' -and '(' -name '*.exe' -or -name '*.dll' -or -name '*.sys' -or -name '*.drv' ')' > found_mod.txt
 
         log_to_file loadsym.sh
 
         log_to_file loadsym.sh
         printf "echo add-symbol-file `cat found_mod.txt` `tail -n 1 sym.tmp`"
+
         printf "echo add-symbol-file `head -n 1 found_mod.txt` `tail -n 1 sym.tmp`"
 
         end_log
 
         end_log
         shell sh loadsym.sh > load_module.gdb
+
         shell (test -s found_mod.txt && sh loadsym.sh) > load_module.gdb
 
         source load_module.gdb
 
         source load_module.gdb
 
  end
 
  end
 +
 
   
 
   
 
  define copy-module-name
 
  define copy-module-name

Revision as of 14:37, 22 August 2007

rossym.gdb

define log_to_file
       set logging file $arg0
       set logging redirect on
       set logging overwrite on
       set logging on
end

define end_log
       set logging off
end

define load-module-nostrip
       set $modname = $arg0
       set $modaddr = $arg1
       printf "Loading module symbols at 0x%x\n", $modaddr
       log_to_file sym.tmp
       printf "%s\n0x%x", ((char *)$name), $modaddr
       end_log
       shell sed -e 's/\..*$//g' < sym.tmp > modname_stripped.txt
       shell find output-i386 -iname `head -n 1 modname_stripped.txt `'.nostrip.*' > found_mod.txt
       shell test -s found_mod.txt || find output-i386 -iname `head -n 1 modname_stripped.txt `.'???' -and '(' -name '*.exe' -or -name '*.dll' -or -name '*.sys' -or -name '*.drv' ')' > found_mod.txt
       log_to_file loadsym.sh
       printf "echo add-symbol-file `head -n 1 found_mod.txt` `tail -n 1 sym.tmp`"
       end_log
       shell (test -s found_mod.txt && sh loadsym.sh) > load_module.gdb
       source load_module.gdb
end


define copy-module-name
       set $ndx     = 0
       while (((KDB_MODULE_INFO*)$modinf)->Name[$ndx])
               set ((char *)$name)[$ndx] = ((KDB_MODULE_INFO*)$modinf)->Name[$ndx]
               set $ndx = $ndx + 1
       end
       set ((char *)$name)[$ndx] = 0
end

define load-all-modules
       set $stack_space = $esp - 1024
       set $modinf  = $stack_space
       set $name    = $stack_space + sizeof(KDB_MODULE_INFO)
       set $index   = 1

       set $result = KdbpSymFindModuleByIndex($index,$modinf)

       while ($result != 0)
               copy-module-name
               printf "Loading symbols for %s\n", ((char *)$name)
               load-module-nostrip $name (((PKDB_MODULE_INFO)$modinf)->Base+0x1000)
               set $index = $index + 1
               set $result = KdbpSymFindModuleByIndex($index,$modinf)
       end
end

define print-modules
       set $stack_space = $esp - 1024
       set $modinf  = $stack_space
       set $name    = $stack_space + sizeof(KDB_MODULE_INFO)
       set $index   = 0

       set $result = KdbpSymFindModuleByIndex($index,$modinf)

       while ($result != 0)
               copy-module-name
               printf "%s \t(%08x)\n", ((char *)$name), (((PKDB_MODULE_INFO)$modinf)->Base+0x1000)
               set $index = $index + 1
               set $result = KdbpSymFindModuleByIndex($index,$modinf)
       end
end

.gdbinit

add-symbol-file output-i386/ntoskrnl/ntoskrnl.nostrip.exe 
source lib/rossym/rossym.gdb
target remote :1234
break RosSymInit
c
fin
fin
fin

Run qemu like 'qemu -hda reactos.img -S -s'

So then you can break at some point later, and when you want to load kernel symbols, do 'load-all-modules'