Debugging question

Linux specific forum
tspivey
New User
New User
Posts: 7
Joined: Wed Jun 13, 2007 12:17 am
Location: Canada

Debugging question

Post 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.
Quin
Addict
Addict
Posts: 1133
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Debugging question

Post 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?
Quin
Addict
Addict
Posts: 1133
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Debugging question

Post 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...
BarryG
Addict
Addict
Posts: 4173
Joined: Thu Apr 18, 2019 8:17 am

Re: Debugging question

Post by BarryG »

It's only been 3 days since posting. That's not long enough to wait for people to have a look.
Quin
Addict
Addict
Posts: 1133
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Debugging question

Post 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.
User avatar
idle
Always Here
Always Here
Posts: 5891
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Debugging question

Post 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.
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: Debugging question

Post 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).
Fred
Administrator
Administrator
Posts: 18207
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Debugging question

Post by Fred »

- ds should without the debugger, I will take a closer look.
Fred
Administrator
Administrator
Posts: 18207
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Debugging question

Post 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.
Quin
Addict
Addict
Posts: 1133
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Debugging question

Post 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!
tspivey
New User
New User
Posts: 7
Joined: Wed Jun 13, 2007 12:17 am
Location: Canada

Re: Debugging question

Post 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:

Code: Select all

OpenConsole()
y=0
x=1/y
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.
Fred
Administrator
Administrator
Posts: 18207
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Debugging question

Post by Fred »

This one could be a regression, I will test
Fred
Administrator
Administrator
Posts: 18207
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Debugging question

Post by Fred »

Should be fixed in next beta
tspivey
New User
New User
Posts: 7
Joined: Wed Jun 13, 2007 12:17 am
Location: Canada

Re: Debugging question

Post by tspivey »

Thanks!
Quin
Addict
Addict
Posts: 1133
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Debugging question

Post by Quin »

Thanks Fred! :)
Post Reply