Page 1 of 1
Debugging question
Posted: Thu May 29, 2025 4:04 pm
by tspivey
I'm trying to debug a crashing application on Linux, and am running into problems. What am I missing?
An example program that will crash is:
y = 0
x = 1/y
I want to create debugging symbols in the binary, so I can debug with gdb. This is a server, so I want it to crash and then automatically restart while running under systemd (I can have it generate a core file).
I'm using the C backend, 6.21 beta 9.
1. -ds by itself doesn't work, the debugging symbols aren't created.
2. -c -d -ds works, it will give me a source file and the debug symbols. However, it also prompts me to run the console debugger on crash (because of -d). How can I control that?
3. I want text printed to STDOUT. Calling OpenConsole() will attempt to trigger the console debugger, but will fail because STDIN can't be read:
Code: Select all
[Debugger Error] Fatal arithmetic error.
[Debugger Error] File: test.pb (Line: 3)
Fatal error. Do you want to open the Debugger console? (Yes, No)
(y,N)
[Debugger Error] Input error from stdin, program is exiting.
Now I'm left with a crashed program and effectively no way to debug it.
Re: Debugging question
Posted: Sat May 31, 2025 9:23 am
by Quin
(bump)\
Anyone got any thoughts on this? It makes debugging applications running as Daemons on Linux incredibly difficult if not outright impossible, and at the very least the debugger trying to read from stdin seems like a bug.
@fred?
Re: Debugging question
Posted: Mon Jun 02, 2025 12:42 pm
by Quin
Seemingly no one cares about this, which is very sad.
PureBasic is seemingly not a good language for TCP server applications. This is the first time in 6 years i've been truly disappointed with PB. The server is now written in Go.
Thanks anyways...
Re: Debugging question
Posted: Mon Jun 02, 2025 1:14 pm
by BarryG
It's only been 3 days since posting. That's not long enough to wait for people to have a look.
Re: Debugging question
Posted: Mon Jun 02, 2025 1:37 pm
by Quin
A three-line test program was provided, with exact versions given, and error messages provided. I frankly very highly doubt that anyone looked at this for more than a few seconds. The debugging situation in PB has sorely let me down in recent weeks, I'm afraid.
Re: Debugging question
Posted: Tue Jun 03, 2025 1:15 am
by idle
I don't know anything about using GDB but you can easily use onerror with asm backend to get the required info of where a programs crashing.
Re: Debugging question
Posted: Tue Jun 03, 2025 8:47 am
by Marc56us
Hi,
I want to create debugging symbols in the binary, so I can debug with gdb. This is a server, so I want it to crash and then automatically restart while running under systemd (I can have it generate a core file).
That's fine for research, but a server application shouldn't rely on its own error handling (Debug) to restart. Errors must be dealt with by the code itself, following a test phase. Besides, you shouldn't put a version into production that contains exploitable debugging instructions.
A program running on a server must be monitored by another (program or script shell) that periodically tests if still running and relaunches if necessary (Kill -HUP ...) (after verifications and sending an e-mail to sysadmin).
Re: Debugging question
Posted: Tue Jun 03, 2025 10:23 am
by Fred
- ds should without the debugger, I will take a closer look.
Re: Debugging question
Posted: Wed Jun 04, 2025 3:09 pm
by Fred
'-ds' was working, but was not fully useful. Starting from 6.21, it should work as expected if you respect this:
- Always use the C Backend when using -ds (gcc will use the '-g' flag to generate symbols for the purebasic.c file)
- A commented purebasic.c will be automatically generated in the current directory
- Don't enable the purebasic debugger
Then, you should be able to set breakpoints using gdb, list source, display variable content etc.
About the 'stdin' error, you get this because you don't create an exe but launching directly trough the compiler. To use the console debugger, you need to create an exe first:
ubuntu:~$ pbcompiler -d bug.pb -o bug.exe
ubuntu:~$ ./bug.exe
I move the topic to linux section as it could be useful for other people.
Re: Debugging question
Posted: Wed Jun 04, 2025 3:34 pm
by Quin
Hi Fred,
Thanks for this! Would it be possible to put all this info in the docs, or are you already on that for 6.21?
Thanks again!
Re: Debugging question
Posted: Wed Jun 04, 2025 3:58 pm
by tspivey
I tried running as an executable on Ubuntu 24.10, and get the same result, using the distribution for Ubuntu 24.04.
Compiling and running this program:
With:
Code: Select all
~/purebasic/compilers/pbcompilerc -d -o test test.pb
./test
Results in:
Code: Select all
[Debugger Error] Fatal arithmetic error.
[Debugger Error] File: test.pb (Line: 3)
Fatal error. Do you want to open the Debugger console? (Yes, No)
(y,N)
[Debugger Error] Input error from stdin, program is exiting.
I've tracked it down to the OpenConsole call. If I don't call that, the prompt works as expected.
Re: Debugging question
Posted: Wed Jun 04, 2025 4:01 pm
by Fred
This one could be a regression, I will test
Re: Debugging question
Posted: Wed Jun 04, 2025 4:30 pm
by Fred
Should be fixed in next beta
Re: Debugging question
Posted: Wed Jun 04, 2025 4:32 pm
by tspivey
Thanks!
Re: Debugging question
Posted: Wed Jun 04, 2025 4:56 pm
by Quin
Thanks Fred!
