I'd like to know if anybody had success with debugging postgres through an IDE (NetBeans or Eclipse) by attaching the debugger to the process and still perform step debugging (stop at breakpoints and watch variables).
For most cases, debugging PostgreSQL isn't significantly different to any other server in this regard.
You determine the process ID of the process you wish to examine, then attach the debugger to it and set breakpoints/watchpoints and continue execution. When you hit the break/watch, examine, step, etc as required.
You can SELECT pg_backend_pid() to get the process ID of the current session.
I usually start psql, SELECT pg_backend_pid(), attach gdb, set my breaks/watches, cont, and in my psql session run whatever I expect to trigger my breakpoint/watchpoint. The same principle applies with IDE debuggers (Visual Studio, Eclipse, NetBeans, whatever).
See: the PostgreSQL wiki for some instructions.
Related
I'm following a tutorial on using lldb. I tried typing process attach -p and I got error: attach failed: Error 1. However in the tutorial a screen pops up asking for "developer tools access needs to take control of another process for debugging to continue". I think this is why it won't work. Why does it not pop up?
What were you trying to debug? On Darwin systems, only processes that opt into being debugged can be, and most shipping apps (including all the system ones) do not opt into being debugged.
Since this isn't an issue with the general permission to debug, but rather the target proces rejecting your attach attempt, you wouldn't see the "Developer Tools" dialog box. You machine is configured to debug, just not this process...
You can test this by building something yourself and then attaching to it.
As you know,eclipse IDE has a convenient attached debugging facility for C project.You can see it from the GUI and you can use this facility to debug process that are already in running status,like daemon process..
My question is that when a process just started and I want to debug it from the begining of the process(i.e. from the first line of main function),how I can do it using the IDE?
I know under Windows,there is a tool called gflag,using this tool we can do some configuraitons before starting the process,and when the process is launched,the gflag can detect this and let the debugger tool(e.g. virtual studio) attach the process automatically.
Do not tell me that use sleep fuction.
Check CDT reverse debugging. You will need GDB 7.0 or later for this feature.
Refer
How_do_I_do_Reverse_Debugging
Open source code with eclipse and double click the left of line number to add a break point. Then you can create a session to debug your application
Environment
Qt 5.6.1
Qt Creator 4.0.1
gdb 7.11
Ubuntu 16.04 LTS
Scenario
C: A client application to communicate with M.
M: A manager process to notify L to launch a new process T.
L: A Launcher process to launch new T by forking itself.
T: A new process running in the background.
I am able to run test application and debug the process C in Qt with gdb. But I am not able to debug the T.
Here is the way I tried to debug the T:
Set breakpoints in both C and T;
When the breakpoint is hit. I use Qt menu option "Debug"->"Start Debugging"->"Attach to running application". To try to attach the debugger to the T process.
This is the problem I am having
Instead of hitting the breakpoints that I set in the T. The gdb always hit an invisible breakpoint in function epoll_wait(). After that, if I continue (F5). The application will keep hanging without hitting any further breakpoints in T. Unless I force stop by using the Qt debug option "Stop Debugger". The application is keep waiting. After I stopped the debugger, the C still breaks in the original breakpoint.
The problem with the debugger in Qt
It seems that Qt uses two different debuggers for different processes. I am thinking it might be caused by the C is hanging. So the T process is keep waiting. But I did not set any breakpoints in wrap_epoll_wait() function I am not sure why gdb breaks there. And in the Qt Debugger. I cannot find a way to switch back to C process to let the process to continue to run. (The Qt debugger component "Threads" drop list is disabled by some reason, I can not select a different thread).
The things I tried
Modified the /etc/sysctl.d/10-ptrace.conf set kernel.yama.ptrace_scope value to 0
Turned the debugger option "Tools->Options->Debugger->GDB Extended->Debug all children" on and off in the Qt.
None of above things changed the fact that the debugger is hanging after the debugger breaks in the function wrap_epoll_wait().
My Question
Anyone at good gdb and Qt knowledge could help me? And let me know how the gdb debug multiple processes works in Qt? How to switch the debugger between different processes and why gdb breaks on somewhere I did not set the breakpoint?
Thank you very much,
Rong
Since T created by forking from L. The gdb settings 'set follow-fork-mode' needs to be set to 'child' in Qt creator.
reference:
https://sourceware.org/gdb/onlinedocs/gdb/Forks.html
i am from java background and have used debugger in eclipse(java).
i have installed postgresql 9.3 as stated in this link: https://wiki.postgresql.org/wiki/Working_with_Eclipse
The debugger works fine for the server(which waits and accepts incoming client connections).
When i connect a client with: $ psql test .Does the server create a new thread for the client?
Is it possible to attach debugger and set breakpoints in parser.c or executor.c in postgresql source files so that i can analyse how postgresql queries are executed?
I have tried attaching debugger and set breakpoints in parser.c and executed some queries in the client.But it doesnt stop at the breakpoint.
Thanks in Advance
When i connect a client with: $ psql test, Does the server create a new thread for the client?
No. The server creates a new postgres (or, on Windows, postgres.exe) process that communicates with the postmaster and other processes via shared memory and signals. PostgreSQL uses a shared-nothing-by-default multiprocessing architecture rather than a shared-everything-by-default multithreading architecture.
Is it possible to attach debugger and set breakpoints in parser.c or executor.c in postgresql source files so that i can analyse how postgresql queries are executed?
Yes, if your debugger can follow backend forks from the postmaster, or if you directly attach your debugger to the backend you wish to debug. The latter is more common unless you're debugging backend startup.
A typical workflow is:
Connect with psql
SELECT pg_backend_pid()
Connect the debugger to that process ID
Set breakpoints and watches as desired and resume execution
In the same psql session, run the query you want to debug backend execution of
Switch to the debugger when it traps and start debugging
This works on Linux with gdb and Windows with Visual Studio. Presumably it works with Eclipse too.
More at the developer FAQ.
It is possible to instead debug the postmaster and use gdb's multi-process debugging features with follow-fork-mode, detach-on-fork, schedule-multiple and non-stop options, but it's complicated to get right, noisy, and will be confusing if you're used to gdb's normal break behaviour. It's also a bit awkward because PostgreSQL uses signals that gdb also uses, so some hacks are required to work around that. See a blog post I wrote on the topic earlier.
I recommend keeping it simple and attaching using pg_backend_pid.
I'm trying to debug for the first time a gtk code and actually, I want to debug a callback function for key-press-event so I set a breakpoint with gdb and when it hits the breakpoint, the whole desktop evirement is freezing (I'm running under gnome-shell) it seems that the graphic envirement is waiting for the event to finish.
I got some idea that didn't worked :
The first attempts was to assign some gdb commands to the breakpoint :
(gdb) break on_key_press_callback
(gdb) commands
> back trace
> next
> next
> next
> continue
> end
but I don't know why, only the back trace command is executed, and then freeze.
The second attempt was to debug remotely using gdbserver and gdb on tty1 (no graphigs to freeze :) ) I was able to send commands like next and step after the breakpoint but there was nothing to see (can't list code, inspect the stack, ect ...)
So any good tips to be able to debug in such situations ?
Thanks
It's typical to have lockups when debugging an X program running on the same server that you're using to debug. For example, if the inferior (gdb terminology for the program being debugged) does a server grab -- whoops, the gdb GUI (or terminal or emacs etc) is locked out.
Your idea of doing more programmatic debugging is a good one, but it's hard to make it all work nicely. As you found, some gdb commands (basically those related to inferior control) don't work in commands. Also, it just isn't nearly as convenient.
You can go further that direction. For example you could use SystemTap to probe the program instead.
However there are also nicer approaches.
One way is to run the inferior using a virtual X server -- a nested one, or one running in a VM. Then you can escape to the "outer" X server for debugging. This will be much nicer.
Another way is to have two computers, and run the debugger on one and the inferior on the other. In a way this is really the same answer, just using a real machine rather than a virtual one.
The question is old, but for anyone that may be struggling with this issue, there is a way to stop the freezing behaviour from happening by disabling the X server grab.
You have to change the config in your IDE to run the program with the following system property:
-Dsun.awt.disablegrab=true
If you are using javaws (Java Web Start) to run the application use:
-J-Dsun.awt.disablegrab=true
instead.