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.
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.
I have a client server program on C. The program has used libraries such as ffmpeg, libfftw3 etc, now I want to run it on my webpage. I have object files as well as executable files compiled from the C programs. I was searching for some platform which will allow me to run the client-server, just like the way a shell script on terminal allows.
Can anyone please tell me how can I do it.
You can run the program "from your web page" if you rebuild your program using Google's Native Client (NaCl) libraries. https://code.google.com/p/nativeclient/
This builds an executable that is run from Chrome, on the users machine, inside a sandboxed environment. The executable is built and distributed in an intermediate, machine independent format that Chrome coverts into a runtime format when it downloads and runs the app.
The performance is good (a little slower than full speed). The downside is that you are limited to the NaCl libraries. And, you have to run the app with Chrome.
If you want to run this in a client-server configuration, you can have the server run on the same machine or on a different machine.
It's easier to write the server program on your own server machine once and communicate via sockets, otherwise you have to port it to all the machines you want it to run on.
If you are interested in running the server on your local machine, you can use WebSockets to connect simple web pages with HTML and JavaScript to the server.
The right approach depends on what your needs are.
I have a server which is running c code and another server where my development environment is present. Can I use something like remote debugging to debug C code on my development server.
I am using unix development and deployment environment.
We all have no idea which environment you use! Win/Linux/Mac/...
On linux:
run gdb with
target remote <ip-number>:<port>
and on the target system:
gdbserver <prog-to-debug>
My suggestion would be, just use ssh to connect to your server, and run a debug session on there (e.g. gdb). The only thing you have to bear in mind is that if you want useful debug output, you probably want to compile leaving debug symbols in, before you deploy (but that is a consideration no matter where you're debugging).
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.
Using gdb, I am trying to trace the function calls of a web server. I set breakpoints on every function call and when I tell gdb to 'run' it breaks at all the right places while the server starts up. Then gdb says 'Program ended with code 01' and doesn't stop at breakpoints anymore (obviously). However, the web server is still running.
I want to be able to trace the function calls made on an incoming HTTP request, so just breaking during server startup is useless to me.
Is there some trick to using gdb when tracing a daemon server so that it doesn't just end like above?
You didn't say which server you are trying to trace, but likely it is Apache.
Detailed instructions are here. Note the -X command line argument, which prevents httpd from forking children.
Also note that the instructions are the first result for this search.
set follow-fork-mode child
see https://sourceware.org/gdb/onlinedocs/gdb/Forks.html for example