News for hackers. Stuff that matters.
Re:GDB 8.1 Released by zython on Wednesday January 31, 2018 @12:29PM (#16275554)
> New shortcuts for TUI Single-Key mode: 'i' for stepi, and 'o' for nexti;

TUI really is one of the best features to really get into gdb. visually stepping through the disassembly really makes debugging more appealing, I really wish they dont abandon this aspect of gdb

Re:GDB 8.1 Released by zython on Wednesday January 31, 2018 @03:25PM (#16277234)
Seems like a I cannot edit my post, but I just remembered this brilliant short talk (15min) about gdb's TUI.

https://www.youtube.com/watch?v=PorfLSr3DDI

It really did change my opinion of gdb in just 15 min.

Re:GDB 8.1 Released by erk__ on Wednesday January 31, 2018 @01:46PM (#16276375)
My favorite visual gdb interface is the one build into emacs esspecially with gbd-many-mode
Re:GDB 8.1 Released by simark1 on Wednesday January 31, 2018 @02:40PM (#16276871)
GDB developers use it extensively, so it's not going to disappear anytime soon. Of course it's far from perfect and there are better visual interfaces for GDB, but the fact that it's a keystroke away is its strong point.
Re:GDB 8.1 Released by scottlu2 on Wednesday January 31, 2018 @12:36PM (#16275643)
Try cgdb.
Re:GDB 8.1 Released by bch on Wednesday January 31, 2018 @01:01PM (#16275910)
Since I was curious enough to look it up: https://cgdb.github.io/
Re:GDB 8.1 Released by jhasse on Wednesday January 31, 2018 @05:11PM (#16278008)
Why not use a real GUI frontend like Visual Studio Code instead?
Re:GDB 8.1 Released by flukus on Wednesday January 31, 2018 @06:08PM (#16278396)
Can you use VSCode as just a debugger? IDE's typically require sacrifices like letting the IDE take over your build process.
Re:GDB 8.1 Released by chillee on Thursday February 01, 2018 @01:03PM (#16284060)
Yep! This is all of the configuration needed to use VSCode as a debugger for Ocaml:

https://i.imgur.com/kY6NuXC.jpg

Re:GDB 8.1 Released by jhasse on Wednesday January 31, 2018 @06:42PM (#16278598)
Yes :) Install the Native Debug extension and then configure the debugger in the launch.json file.
Re:GDB 8.1 Released by xuhu on Wednesday January 31, 2018 @01:38PM (#16276278)
starti, rbreak and ptype sound good even if they've been available as idioms before.
Re:GDB 8.1 Released by ebeip90 on Wednesday January 31, 2018 @03:34PM (#16277296)
starti did not exist before, and specifically addresses a StackOverflow question of mine from ~3 years ago: https://reverseengineering.stackexchange.com/questions/8724

ptype already existed, but did not print out offsets. This is incredibly useful, and something Windbg does with dt. Pwndbg does this in GDB by adding new commands.

Re:GDB 8.1 Released by rurban on Wednesday January 31, 2018 @06:40PM (#16278588)
Does this mean p does not work anymore, because there are now 2 commands starting with p? This would be a shame.
Re:GDB 8.1 Released by rurban on Thursday February 01, 2018 @06:58AM (#16281213)
I checked it out. p still works as before.

But I needed a C++ patch on osx with cc/clang. Apparently they added cxx files with the .c extension: gdb/probe.c:63

    - const any_static_probe_ops any_static_probe_ops;
    + any_static_probe_ops any_static_probe_ops;
Re:GDB 8.1 Released by akrasuski1 on Wednesday January 31, 2018 @07:43PM (#16278887)
Presumably the stackexchange answer is what OP meant by it being an idiom.
Re:GDB 8.1 Released by kazinator on Wednesday January 31, 2018 @01:30PM (#16276208)
I'd really like a way for a program to have an API for interacting with GDB: with that it could tell "I'm running under a debugger". There would be a file descriptor which talks to the debugger, if the debugger is present. Output sent to it goes to the debugger and perhaps it could obtain input from the debugger also. Maybe the API could provide some introspection: the program could ask what breakpoints have been set and things like that.
Re:GDB 8.1 Released by modeless on Wednesday January 31, 2018 @02:08PM (#16276575)
Having the program behave differently under a debugger is a great way to introduce bugs that disappear when the debugger is present. Any features of this type would have to be completely optional.
Re:GDB 8.1 Released by kazinator on Wednesday January 31, 2018 @02:29PM (#16276770)
Any optional features are a good way to have an application behave differently when the option is on, versus off. :)

Programs behave differently under a debugger anyway; "bugs disappearing under a debugger" already happens now.

It's just a question of the risk/reward.

"This debugger feature increases the scope of situations when a bug disappears under the debugger": that's a risk.

"This debugger feature gives me a better overall debugging experience most of the time": benefit

Re:GDB 8.1 Released by dustfinger on Wednesday January 31, 2018 @02:19PM (#16276684)
Yes, and introducing bugs is not the only issue at stake.

Imagine malware that could react differently when a debugger is attached.

Re:GDB 8.1 Released by jcelerier on Wednesday January 31, 2018 @04:13PM (#16277592)
> Imagine malware that could react differently when a debugger is attached.

that has been the case for a long time: simply timing some instructions is generally enough to tell you that you're running under a debugger. It's also helpful for copy protection.

Re:GDB 8.1 Released by ChrisLomont on Wednesday January 31, 2018 @02:31PM (#16276797)
Malware already does this on many platforms via many methods, and has done so for perhaps decades.

Here's [1] the tip of the iceberg on this issue.

[1] antukh.com/blog/2015/01/19/malware-techniques-cheat-sheet/

Re:GDB 8.1 Released by kazinator on Wednesday January 31, 2018 @02:30PM (#16276785)
The debugger could have a mode of "stealth attachment" under which that feature is not activated; the connection with that special interface is not made, and so the program is not informed that it's under a debugger, and those debug streams don't connect to anything.
Re:GDB 8.1 Released by dustfinger on Wednesday January 31, 2018 @02:32PM (#16276803)
Well, to be fair malware already exists that can detect when a system debugger is attached so maybe my concern is invalid. I guess the greater concern is the introduction of bugs after all.

Edit - Other commenters beet me to this point :-P

Re:GDB 8.1 Released by kazinator on Wednesday January 31, 2018 @02:40PM (#16276865)
The program is what it is and it has bugs. There is a risk that bugs are irreproducible under a debugger (no matter how transparent the debugger). Oh well; you have to debug those in some other way. That risk shouldn't paralyze us from innovating debuggers.

There are bugs that won't reproduce when you debug via JTAG; so what.

Simply pausing on a breakpoint can make a bug irreproducible.

Programs can infer that they are being debugged via timings, and various side channels.

Re:GDB 8.1 Released by saagarjha on Wednesday January 31, 2018 @03:26PM (#16277239)
The issue is that by introducing this feature, you're increasing the number of programs that behave differently when a debugger is attached. Just because this can be an issue today doesn't mean that we should make it even more of an issue tomorrow.
Re:GDB 8.1 Released by stouset on Wednesday January 31, 2018 @02:31PM (#16276793)
Malware already does this. Non-malware programs already do this to complicate analysis.
Re:GDB 8.1 Released by kazinator on Wednesday January 31, 2018 @02:42PM (#16276884)
If those non-malware programs are fixed to use a proper API instead of side channel hacks, then it simplifies analysis.
Re:GDB 8.1 Released by saagarjha on Wednesday January 31, 2018 @02:59PM (#16277016)
> If those non-malware programs are fixed to use a proper API instead of side channel hacks, then it simplifies analysis.

I think you’re missing the point as to why programs would do this. Usually it’s to protect some sort of DRM scheme through obscurity.

Re:GDB 8.1 Released by jburgess777 on Wednesday January 31, 2018 @05:02PM (#16277953)
Something like this is already supported by the GDB "remote" protocol:

https://sourceware.org/gdb/onlinedocs/gdb/Remote-Protocol.ht...

In your program you would probably need to link in some code to implement the protocol, like the GDB remote stub:

https://sourceware.org/gdb/onlinedocs/gdb/Remote-Stub.html

Qemu and Valgrind both implement their own gdb stubs.

For ARM targets, there is a similar feature named "semihosting":

http://www.keil.com/support/man/docs/armcc/armcc_pge13587870...

Re:GDB 8.1 Released by kazinator on Wednesday January 31, 2018 @05:46PM (#16278251)
So that's a different approach: integrate a remote debugging GDB server into the program (could be a shared lib that is dlopen-ed, by the way). Then that server is always used, even in a local session. The server is deeply integrated into the program, taking advantage of the protocol to communicate between application code and the debugging client.

It sounds promising. A particularly interesting area is events:

https://sourceware.org/gdb/onlinedocs/gdb/Notification-Packe...

The program could generate custom notifications.

Re:GDB 8.1 Released by wazari972 on Wednesday January 31, 2018 @01:42PM (#16276334)
this is not particularly hard to do with the Python interface: you define structures that are known by the process and the Python module + global variables, then you set an internal (silent) breakpoint on a given 'event' function. In the program you fill the structure with some queries, and in the Python breakpoint callback, you process it as you need. This is the way multi-thread debugging work (used to at least), shared library detection as well...
Re:GDB 8.1 Released by kazinator on Wednesday January 31, 2018 @02:36PM (#16276831)
Okay, good ideas there: so the program has some standard dispatch function that can be called to talk to the debugger. Normally that does nothing. The debugger can recognize this function and stick a breakpoint in it to alter the behavior.

The function can do something like put a request into a mailbox buffer, and then check for a reply in the inbox buffer. When there is no debugger, there is never any reply.

When the debugger stops the show with the breakpoint, it processes the request and prepares a reply, flipping some "reply present" flag; when the program is resumed then, it gets the reply.

It would be good not have any of that damned Python monkey business involved in this.

Re:GDB 8.1 Released by wazari972 on Wednesday January 31, 2018 @03:07PM (#16277080)
> It would be good not have any of that damned Python monkey business involved in this.

please, GDB internals are open source, you can do all of that in plain C :D That's what I did initially, to give GDB the ability to distinguish user-level threads (see libthread_db).

Having a high-level language / interface to GDB is a great again of time !

Re:GDB 8.1 Released by monocasa on Wednesday January 31, 2018 @03:05PM (#16277058)
I'm a little unclear as to what your end goal is.
Re:GDB 8.1 Released by kazinator on Wednesday January 31, 2018 @05:51PM (#16278293)
One use case would be to have some debug_printf() in the program that shows up in the debugger, no matter whether the debugger is remote or local. It doesn't go to some console, or file, but always to the debugger.

The Microsoft environment has something like this: OutputDebugString. Very useful.

https://msdn.microsoft.com/en-us/library/windows/desktop/aa3...

Also IsDebuggerPresent: https://msdn.microsoft.com/en-us/library/windows/desktop/ms6...

and other things.

The debugging experience on Windows 20+ years ago was was ahead of debugging on GNU/Linux today, I'm afraid, so this stuff is above criticism from the "M$ SuX" angle.

Re:GDB 8.1 Released by monocasa on Wednesday January 31, 2018 @06:18PM (#16278457)
You don't need OutputDebugString on because you can always tap the write syscall on stdout from gdb.

And I don't really know what IsDebuggerPresent gets you.

You're really focusing on features, rather than use cases.

Re:GDB 8.1 Released by kazinator on Wednesday January 31, 2018 @09:40PM (#16279321)
Well, stdout isn't a debug channel; you might want to debug a program that actually uses stdout for its output, not for debug chatter.

Never mind that though, we can take some other descriptor, like 3, and bind it to, say /dev/null.

What are the gdb commands to have whatever is going to file descriptor 3 be shown inside gdb?

I really do not care how it's implemented. However, "tightly integrated" is better than "flimsy hack"; "consumes breakpoints" is better than "doesn't consume breakpoints".

Re:GDB 8.1 Released by flukus on Wednesday January 31, 2018 @11:49PM (#16279699)
> Well, stdout isn't a debug channel; you might want to debug a program that actually uses stdout for its output, not for debug chatter.

What's your use case for this that makes stderr unsuitable?

Re:GDB 8.1 Released by kazinator on Thursday February 01, 2018 @01:13PM (#16284164)
stderr also isn't for debug output.

If, say, a compiler puts out "hello.c: syntax error" on its standard error stream, that is not a debugging diagnostic regarding that compiler's internals; it's about "hello.c".

stderr is not an instrumentation tool which goes away when we're not debugging the program.

Re:GDB 8.1 Released by monocasa on Thursday February 01, 2018 @01:32PM (#16284390)
Why? It's not like it'd be printing debugging level messages on release builds in either case.
Re:GDB 8.1 Released by purplezooey on Wednesday January 31, 2018 @01:17PM (#16276075)
heh. Has anyone ever used gdb to debug Pascal? :)
Re:GDB 8.1 Released by rivert on Wednesday January 31, 2018 @01:36PM (#16276264)
I have to, on a regular basis actually and I'm glad gdb and FPC work well together.
Re:GDB 8.1 Released by agumonkey on Wednesday January 31, 2018 @01:56PM (#16276462)
Nice to hear, I have a pascal lisp project I need to revive, having gdb on my side would help
Re:GDB 8.1 Released by purplezooey on Thursday February 01, 2018 @06:49PM (#16287067)
That's awesome! They taught Pascal in my CS undergrad classes.
Re:GDB 8.1 Released by gramstrong on Wednesday January 31, 2018 @01:28PM (#16276182)
I might have used it to debug Ada, which is like Pascal, back when I was in school.
Re:GDB 8.1 Released by rom1v on Wednesday January 31, 2018 @11:54AM (#16275267)
Cool, but why are the release checksums in MD5?
Re:GDB 8.1 Released by dmm on Wednesday January 31, 2018 @12:28PM (#16275543)
MD5 is fine for verifying a download is not corrupted, so that's probably the intended use.
Re:GDB 8.1 Released by lucb1e on Wednesday January 31, 2018 @12:30PM (#16275564)
For that purpose, TCP already includes a CRC32. I'd say cryptographic hashes are generally meant for more than corrupted downloads.
Re:GDB 8.1 Released by tonyg on Wednesday January 31, 2018 @04:59PM (#16277929)
TCP's checksum isn't even as good as CRC32. It's just a one's-complement sum of the packet and a few header words.

From this [0] helpful StackOverflow post:

> If you need to transfer data and you want to be sure the data didn't get corrupted, the TCP checksum alone is certainly not enough for this task. I would even dare to say that a CRC checksum is not enough for this task, since a CRC32 may not detect an error where more than 32 bits in a row are affected (these errors can "cancel out" each other). The minimum checksum you'd need for ensuring flawless data transfer is the MD5 value of the data.

[0] https://stackoverflow.com/questions/3830206/can-a-tcp-checks...

Re:GDB 8.1 Released by alanfranzoni on Wednesday January 31, 2018 @12:32PM (#16275601)
Which is not that hard to fool on large files with multiple, sistemic errors.
Re:GDB 8.1 Released by harikb on Wednesday January 31, 2018 @01:22PM (#16276112)
File checksums are typically used when the checksum is still on the master site but the file could be in untrusted mirrors. TCP level stuff is useless in those scenarios.
Re:GDB 8.1 Released by guipsp on Wednesday January 31, 2018 @02:01PM (#16276496)
So is md5
Re:GDB 8.1 Released by rwmj on Wednesday January 31, 2018 @03:22PM (#16277196)
I have a machine which randomly zeroes blocks of 32 bytes in HTTP downloads [thought to be a cache-related fault] and TCP doesn't catch this.
Re:GDB 8.1 Released by bjoli on Wednesday January 31, 2018 @12:17PM (#16275461)
I don't know, but they also have gpg .sig-files in the download folder.
Re:GDB 8.1 Released by Boxxed on Wednesday January 31, 2018 @02:21PM (#16276695)
Ah yes, the standard nitpicky dismissive HN comment makes its appearance.
Re:GDB 8.1 Released by qubex on Wednesday January 31, 2018 @03:16PM (#16277137)
I’m quite amazed we’ve made it to 33 comments without somebody complaining it the project hasn’t been retooled with Rust/Clojure/Node.js yet.
Re:GDB 8.1 Released by Maken on Thursday February 01, 2018 @12:28PM (#16283733)
There is no point on reimplementing GDB yet, you need first a legacy debugger with proper Rust support until the new one can debug itself.
Re:GDB 8.1 Released by Rexxar on Wednesday January 31, 2018 @09:12PM (#16279243)
I see just a question, nothing "nitpicky dismissive" ? Has the comment been edited into a more neutral tone ?
Re:GDB 8.1 Released by rom1v on Wednesday January 31, 2018 @03:22PM (#16277198)
Fair enough.

I had nothing interesting to say about the new GDB release, but the checksum used surprised me. Hence the question.