Pass gdb commands on command-line - gdb

This answer describes how you can manipulate the debugging environment when running gdb interactively. The specific suggestion is to use the following command aid in catching a Heisenbug.
(gdb) set disable-randomization off
However, when using gdb from the command-line, you lose a lot of amenities that you would have with a graphical debugging front end (such as nemiver or kdbg). I am using kdbg, which allows me to specify a command-line for use when invoking gdb. Is there a command-line argument that achieves the same results as the interactive command shown above?

Related

How to set breakpoint on all functions in a C++ file using VS Code

We can use following gdb command to set breakpoint in all functions in a file:
(gdb) rbreak file.cpp:.*
Is there a way to achieve the same feature when debugging from VSCode?
I am assuming that you are debugging in VS Code using the GDB debugger (and not the Visual Studio Windows Debugger).
GDB, LLDB, and LLDB-MI Commands (GDB/LLDB) For the C++ (GDB/LLDB) debugging environment, you can execute GDB, LLDB and LLDB-MI commands
directly through the debug console with the -exec command, but be
careful, executing commands directly in the debug console is untested
and might crash VS Code in some cases
quoted from https://code.visualstudio.com/docs/cpp/cpp-debug
as Alan Birtles said in a comment to you question, you should be able to enter the gdb command here

Sending GDB commands into CLion

I'm experiencing the Heisenbug on my program and this post suggested me to execute the command set disable-randomization off into GDB. However, I have no idea how to execute a GDB command in CLion and when I should do so. The GDB tab in the debugging remain uneditable when I try to copy paste my command.
How can I execute my command? Do I need to debug without CLion?
In debug mode, you can enter LLDB (presumably also GDB) commands using the following interface

Emacs and gdb - Show code for function in backtrace

I am debugging a C++ program. Suppose I am sitting at a breakpoint in gdb and I do bt 50. This will generate the backtrace and show me the call stack with 50 functions that were run in the process of execution reaching where it is now.
Sometimes, I want to quickly examine the code for one of the functions in the backtrace call stack. I know how to do this on Visual Studio. Visual Studio maintains call stack similar to gdb backtrace. On Visual Studio, I can simply double-click a function in the call stack and Visual Studio takes me to the code for that function, even opening the file for me if not opened. Very convenient.
I was wondering if there was a gdb command to show code around a symbol name in backtrace. Currently, the only way I know is to manually find the file and open it in emacs, and then do a search in emacs to take me to the function. Please tell me if there is a better way so it becomes convenient like in Visual Studio.
There are several choices, depending on how you are running gdb.
One simple way is to run gdb inside emacs. You can use M-x gdb (or M-x gud-gdb, which is a bit more old-school) to do this. When running gdb in emacs, simply selecting a frame will cause the source to be visited in emacs, and point will move to the line in question. "Selecting a frame" can be done via the up, down, and frame commands.
If you're running gdb outside of emacs, and want to continue doing this, then there are still options.
One approach is the edit command. Make sure to set your EDITOR environment variable to use emacsclient and set up emacs to respond to this (like M-x server-start).
Then in gdb, select some frame and you can see that frame's source with edit *$pc.
Another approach that some people like is to use the gdb "tui". This is a curses-based interface that shows the source in the terminal.
Yet another approach is to use one of the many gdb GUIs.

Debugging C/C++ code with IPython

Say I am in IPython (e.g. on the new QT console), and that I call a C++ library that I wrote from it (e.g. using SWIG or Boost.Python). I would like to set a breakpoint in my C++ code and have the ability to interact with my C++ workspace (i.e. my variables when I hit the breakpoint) with IPython (e.g. plot my C++ variables, etc.).
In other words I would like to debug my C++ code from IPython. Is this at all possible? What are some tools I can use for this?
(assuming you are on Linux)
You just need gdb. First set up configuration telling gdb where your source files are by adding this to $HOME/.gdbinit:
directory absolute-path-to-source
Now start gdb python and on the gdb prompt do:
set args /usr/bin/ipython
run
You can't directly do gdb ipython because ipython is a script. Please refer to the gdb documentation from here on.
In general, you won't be able to debug C++ code directly with IPython. What you can do, though, is use a C++ debugger to debug your C++ code.
Essentially, you tell your C++ debugger to execute whatever process you need to use to run your code (this could be IPython itself), and set a breakpoint in your C++ code (your debugger will know to wait for the appropriate DLL to be loaded if it's in a DLL). From there, you are debugging your part of the code that is running in the IPython process.

Is there any enhanced gdb console for Eclipse?

Currently the gdb console of Eclipse just connects the stdin/stdout between the java gui and the underlying gdb process, hence many gdb shell features are missing, e.g. tab-autocomplete, command history etc.
I want to know if there is an enhanced console for fast gdb interacting. I really like the frequently used gdb commands like "print" and "call" etc. IMHO, "print" command is superiors sometimes than Eclipse "Expression watcher" because it only execute once and the later will be evaluated any time and be crash-prone.
If you think there is no need to use gdb console, then what's you best-practise in terms of gdb UI to eclipse UI transfer.
There doesn't seem to be any gdb-specific plugin, beside the initial gdb integration initiated with Eclipse3.4.
And the current list of gdb bugs doesn't include your missing features.
If you're writing c/++, why not just find the eclipse-generated elf and use gdb via the shell?