Author Topic: issue when I try to auto load GDB python pretty printer  (Read 6037 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6077
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
issue when I try to auto load GDB python pretty printer
« on: July 21, 2014, 03:01:06 am »
Hi, I have a test.exe, and also have a test-gdb.py. The test-gdb.py is a pretty printer associated with test.exe. The expect way is that when GDB load the test.exe, the test-gdb.py is also loaded. This is called: Debugging with GDB: Python Auto-loading

Now, I have correctly set the auto loading option in a user custom .gdb file which is E:\code\gdb\mybuild\bin\my.gdb
Code
...
set auto-load safe-path /
set auto-load python-scripts on

But I found an issue that the custom my.gdb is executed AFTER gdb loading the exe file, so this pretty printer is not loaded. See the debugger plugin log:

Quote
Selecting target:
Debug
Adding source dir: E:\code\cb\test_code\auto-load-python-pretty-printer\
Adding source dir: E:\code\cb\test_code\auto-load-python-pretty-printer\
Adding file: E:\code\cb\test_code\auto-load-python-pretty-printer\bin\Debug\test.exe
Changing directory to: E:/code/cb/test_code/auto-load-python-pretty-printer/.
Set variable: PATH=.;D:\mingw-builds\473\mingw32\bin;D:\mingw-builds\473\mingw32;E:\code\msys\PortableGit-1.9.4-preview20140611\cmd;E:\code\common_bin;D:\opencv246build\build-gcc482-release\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\wbem;D:\Program Files\TortoiseSVN\bin;E:\code\DrMemory-Windows-1.6.1-2\bin;E:\code\wx-mingw-build-481-dw2\wxWidgets-2.8.12\lib\gcc_dll

[debug]Command-line: E:\code\gdb\mybuild\bin\gdb.exe -nx -fullname  -quiet  -args E:/code/cb/test_code/auto-load-python-pretty-printer/bin/Debug/test.exe
[debug]Working dir : E:\code\cb\test_code\auto-load-python-pretty-printer

Starting debugger: E:\code\gdb\mybuild\bin\gdb.exe -nx -fullname  -quiet  -args E:/code/cb/test_code/auto-load-python-pretty-printer/bin/Debug/test.exe
done

[debug]> set prompt >>>>>>cb_gdb:
[debug]Skip initializing the scripting!

Setting breakpoints

[debug]Reading symbols from E:/code/cb/test_code/auto-load-python-pretty-printer/bin/Debug/test.exe...done.
[debug]To enable execution of this file add
[debug]   add-auto-load-safe-path E:\code\cb\test_code\auto-load-python-pretty-printer\bin\Debug\test-gdb.py
[debug]line to your configuration file "$HOME/.gdbinit".
[debug]To completely disable this security protection add
[debug]   set auto-load safe-path /
[debug]line to your configuration file "$HOME/.gdbinit".
[debug]For more information about this security protection see the
[debug]"Auto-loading safe path" section in the GDB manual.  E.g., run from the shell:
[debug]   info "(gdb)Auto-loading safe path"
[debug](gdb) >>>>>>cb_gdb:
[debug]> show version
[debug]GNU gdb (GDB) 7.8.50.20140717-cvs
[debug]Copyright (C) 2014 Free Software Foundation, Inc.
[debug]License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
[debug]This is free software: you are free to change and redistribute it.
[debug]There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
[debug]and "show warranty" for details.
[debug]This GDB was configured as "mingw32".
[debug]Type "show configuration" for configuration details.
[debug]For bug reporting instructions, please see:
[debug]<http://www.gnu.org/software/gdb/bugs/>.
[debug]Find the GDB manual and other documentation resources online at:
[debug]<http://www.gnu.org/software/gdb/documentation/>.
[debug]For help, type "help".
[debug]Type "apropos word" to search for commands related to "word".
[debug]>>>>>>cb_gdb:
[debug]> set confirm off

Debugger name and version: GNU gdb (GDB) 7.8.50.20140717-cvs

[debug]>>>>>>cb_gdb:
[debug]> set width 0
[debug]>>>>>>cb_gdb:
[debug]> set height 0
[debug]>>>>>>cb_gdb:
[debug]> set breakpoint pending on
[debug]>>>>>>cb_gdb:
[debug]> set print asm-demangle on
[debug]>>>>>>cb_gdb:
[debug]> set unwindonsignal on
[debug]>>>>>>cb_gdb:
[debug]> set print elements 0
[debug]>>>>>>cb_gdb:
[debug]> set new-console on
[debug]>>>>>>cb_gdb:
[debug]> set disassembly-flavor intel
[debug]>>>>>>cb_gdb:
[debug]> catch throw
[debug]Catchpoint 1 (throw)
[debug]>>>>>>cb_gdb:
[debug]> source E:\code\gdb\mybuild\bin\my.gdb
[debug]>>>>>>cb_gdb:
[debug]> directory E:/code/cb/test_code/auto-load-python-pretty-printer/
[debug]Source directories searched: E:/code/cb/test_code/auto-load-python-pretty-printer;$cdir;$cwd
[debug]>>>>>>cb_gdb:
[debug]> break "E:/code/cb/test_code/auto-load-python-pretty-printer/main.cpp:16"
[debug]Breakpoint 2 at 0x4015de: file E:\code\cb\test_code\auto-load-python-pretty-printer\main.cpp, line 16.
[debug]>>>>>>cb_gdb:
[debug]> run
[debug]Starting program: E:\code\cb\test_code\auto-load-python-pretty-printer\bin\Debug\test.exe

Child process PID: 588

[debug][New Thread 588.0xa90]
[debug]Breakpoint 2, main () at E:\code\cb\test_code\auto-load-python-pretty-printer\main.cpp:16
[debug]E:\code\cb\test_code\auto-load-python-pretty-printer\main.cpp:16:131:beg:0x4015de
[debug]>>>>>>cb_gdb:

At E:\code\cb\test_code\auto-load-python-pretty-printer\main.cpp:16

[debug]> bt 30
[debug]#0  main () at E:\code\cb\test_code\auto-load-python-pretty-printer\main.cpp:16
[debug]>>>>>>cb_gdb:

> show auto-load python-scripts

[debug]> show auto-load python-scripts
[debug]Auto-loading of Python scripts is on.
[debug]>>>>>>cb_gdb:

Auto-loading of Python scripts is on.
> info auto-load python-scripts

[debug]> info auto-load python-scripts
[debug]Loaded  Script                                                                
[debug]No      E:\code\cb\test_code\auto-load-python-pretty-printer\bin\Debug\test-gdb.py
[debug]>>>>>>cb_gdb:

Loaded  Script                                                                
No      E:\code\cb\test_code\auto-load-python-pretty-printer\bin\Debug\test-gdb.py


A possible fix is that firstly start gdb.exe, and run my.gdb, and finally load the test.exe.

BTW: I'm going to test the auto load python pretty printer associated with DLL file, I think it don't have this issue, because DLL files are loaded later after running the exe file.

EDIT: Yes, confirmed, no issue with python pretty printer auto load with DLL.
« Last Edit: July 21, 2014, 04:20:25 am by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6077
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: issue when I try to auto load GDB python pretty printer
« Reply #1 on: July 21, 2014, 04:34:58 am »
OK, problem solved, I just add those command in the Debugger initial argument (in debugger plugin setting dialog)
Code
-iex "set auto-load safe-path /"
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.