Difference between revisions of "Rossym.gdb"

From ReactOS Wiki
Jump to: navigation, search
 
(Categories)
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
== rossym.gdb ==
 
== rossym.gdb ==
  
{{{
+
<code>
 
  define log_to_file
 
  define log_to_file
 
         set logging file $arg0
 
         set logging file $arg0
Line 8: Line 8:
 
         set logging on
 
         set logging on
 
  end
 
  end
 
+
 
  define end_log
 
  define end_log
 
         set logging off
 
         set logging off
 
  end
 
  end
 
+
 
  define load-module-nostrip
 
  define load-module-nostrip
 
         set $modname = $arg0
 
         set $modname = $arg0
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
 
         set $ndx    = 0
 
         set $ndx    = 0
Line 37: Line 38:
 
         set ((char *)$name)[$ndx] = 0
 
         set ((char *)$name)[$ndx] = 0
 
  end
 
  end
 
+
 
  define load-all-modules
 
  define load-all-modules
 
         set $stack_space = $esp - 1024
 
         set $stack_space = $esp - 1024
Line 43: Line 44:
 
         set $name    = $stack_space + sizeof(KDB_MODULE_INFO)
 
         set $name    = $stack_space + sizeof(KDB_MODULE_INFO)
 
         set $index  = 1
 
         set $index  = 1
 
+
 
         set $result = KdbpSymFindModuleByIndex($index,$modinf)
 
         set $result = KdbpSymFindModuleByIndex($index,$modinf)
 
+
 
         while ($result != 0)
 
         while ($result != 0)
 
                 copy-module-name
 
                 copy-module-name
Line 54: Line 55:
 
         end
 
         end
 
  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
 +
</code>
  
 
== .gdbinit ==
 
== .gdbinit ==
  
{{{
+
<code>
 
  add-symbol-file output-i386/ntoskrnl/ntoskrnl.nostrip.exe  
 
  add-symbol-file output-i386/ntoskrnl/ntoskrnl.nostrip.exe  
 
  source lib/rossym/rossym.gdb
 
  source lib/rossym/rossym.gdb
Line 67: Line 84:
 
  fin
 
  fin
 
  fin
 
  fin
}}}
+
</code>
 +
 
 +
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'
 
So then you can break at some point later, and when you want to load kernel symbols, do 'load-all-modules'
 +
[[Category:Kernel]]

Latest revision as of 05:27, 2 March 2012

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'