Change NetBeans Debugger Command - c++

I have a .gdbinit file to set the solib-absolute-prefix and solib-search-path when attaching a debugger from NetBeans. I've turned on the debugger console (by adding -J-Dgdb.console.window=true to netbeans_default_options in /usr/share/netbeans/6.9/etc/netbeans.conf) and it tells me:
Debugger Command: [/path/to/gdb, -nx, --nw, --silent, --interpreter=mi]
The -nx is preventing it from loading my .gdbinit file.
Is there any way in NetBeans to either (1) remove -nx from that command, (2) specify a .gdbinit file to load with gdb, or (3) specify library search paths explicitly?

Never mind, you can add -J-Dgdb.init.enable=trueto netbeans_default_options in /usr/share/netbeans/6.9/etc/netbeans.conf and it will load the .gdbinit file.

Related

How to specify .so path to use with GDB whan analysing dump file?

I have a crash dump that I want to analyse with GDB on different computer. Crashed application uses several shared libraries (*.so files). I want GDB to load symbols from some of them but I can't put all of them in the original path.
Adding LD_LIBRARY_PATH to the environment doesn't help when working with dumps. When I type info shared it shows full (non-relative) paths:
(gdb) info shared
From To Syms Read Shared Object Library
0x00007fad4fb7f220 0x00007fad4fb80179 Yes /lib/x86_64-linux-gnu/libdl.so.2
...
No /opt/app/libXXX.so
...
How to specify different path for the example libXXX.so (from gdb command line or command prompt)?
The set solib-search-path option is for that purpose. Documentation says it is ment for using with gdbserver but also works with dump analysis. By default, it is set to ., so the directory that gdb is run from.
BUT: for some reason it doesn't work out of the box (at least with gdb 10.2). I don't know the reason, but I know a workaround: just type set solib-search-path . as a first command after entering gdb prompt. The output is following for me:
(gdb) set solib-search-path .
Reading symbols from /home/example/path/libXXX.so...
Of course one can type any path she want instead of ..

how can I make gdb ignore .gdbinit

I have set up my ~/.gdbinit with some commands for a specific configuration.
Sometimes I would like to start gdb to ignore the .gdbinit.
Is there a mechanism to ignore .gdbinit or override it by another .gdbinit?
Run GDB with
gdb -nx
This skips the .gdbinit file processing.
According to GDB docs, Initialization Files You want to skip your "Home directory early initialization files", to do so start GDB with -nh.
The accepted answer -nx also disables the "System wide initialization files" and the "Local directory initialization file".

GDB exec Error: No such file or directory

I have an executable, which I can read symbols from (so it seems.) My problem is this: when it comes time to run, I get the following error:
(gdb) run
Starting program: /home/usr/src/etcetera/etcetera/bin/theExecutable.exe
Cannot exec -c exec /home/usr/src/etcetera/etcetera/bin/theExecutable.exe.
Error: No such file or directory
During startup program exited with code 127
obviously, I have edited the directories here. I searched how to fix this on SO, and tried some of the following solutions:
GDB cannot see source file
GDB can't find source file
GDB won't load source file
got onto this link:
https://sourceware.org/gdb/download/onlinedocs/gdb/Source-Path.html#Source-Path
and am trying to change the source file directory. (The source files are not in the same location as the executable, but instead are spread over a range of different places.) Unless I am mistaken, the way of doing this is to go:
(gdb) directory /home/usr/src/etcetera/etcetera/rootDirectoryForSourcefiles
and have the GDB search this directory. I have even tried changing directory into the source directory, and then running but still, it wants to try where the executable lives.
Am I completely missing the mark here in an obvious way, or is this likely to be quite obscure?
You are barking up the wrong tree. You problem has ~nothing to do with source files, and everything to do with your executable file.
It may be related to something in your ~/.gdbinit, or your ~/.bashrc, or the way you invoked GDB.
You should start by doing a basic sanity check:
env SHELL=/bin/sh gdb -nx /bin/date
(gdb) run
If that doesn't work, your GDB installation is screwed up.
If that does work, one of the three things I mentioned above is very likely the cause of your troubles.
I had this problem and it turned out that the shell wasn't set correctly in the /etc/passwd file.
To solve it, I opened the file with
sudo vipw
and added /bin/bash to the my account's data there.
Try to:
export SHELL=/bin/sh
before running gdb
I had met same problem. When my
SHELL=/usr/local/bin/tcsh
but I have only the file .cshrc, gdb reports the same error.
When I change SHELL:
setenv SHELL /bin/csh
Then everything goes fine.

How GDB startup files work?

How do I save my current GDB session? and How do I load it again on GDB startup later. There is a brief discussion on .gdbinit in Art of debugging , Chapter 1. But I really don't get the saving part. Is it an autosave?
The .gdbinit file saves some configurations and user-defined commands. When gdb starts, it will try to search .gdbinit file according to some sequences (For the sequences, you can refer https://sourceware.org/gdb/current/onlinedocs/gdb/Mode-Options.html#Mode-Options). For .gdbinit file, you can refer this as an example:https://github.com/gdbinit/Gdbinit/blob/master/gdbinit.
I think you want to store the whole memory dump into the file, then restart gdb, it will reload it. I have search the invoking gdb manual(https://sourceware.org/gdb/current/onlinedocs/gdb/Invoking-GDB.html#Invoking-GDB), but can't find gdb can do it.
Personally, I think this file you request is very similar to core dump file.

How to save settings in gdb?

Does anyone know how to save gdb settings (like "set print pretty on" or "set print elements 0", both from here)? I don't want to set my configuration every time that I will use gdb :/
I searched in google and SO, but I found nothing.
Add any commands you want to auto run in the .gdbinit file in your home directory.
The existing answer works for commands that can run before the binary is loaded, but for example if you want to add catch throw you cannot do it in .gdbinit since that command needs to run after the binary is loaded.
But gdb can take a file with commands to run after binary loading using:
-x file
Execute GDB commands from file file.
I automated that by creating an alias:
alias gdb='gdb -x ~/.gdbinit_x'
and added my after binary load commands in that file.