Hi tech,
I have a problem and I have ad hoc patch to solve this problem.
However, this patch is AD HOC. Does anybody have correct solution?
The next command of GDB does not work properly.
I use OpenBSD 6.3 and /usr/bin/gdb (GDB 6.3).
When I debuging my program with next command, I expect stop at next
line. However, program returned from current function unusual.
It seems that this problem will occur if there is a WHILE immediately
after the function call.
Example as below:
$ uname -a
OpenBSD asou-obsd63.soum.co.jp 6.3 GENERIC#100 amd64
$ cat main.c
#include <err.h>
#include <locale.h>
#include <stdio.h>
#include <unistd.h>
int
main(int argc, char *argv[])
{
extern void sub(int);
int ch;
int flag_a = 0;
sub(1);
while ((ch = getopt(argc, argv, "a")) != -1) {
switch (ch) {
case 'a':
flag_a = 1;
break;
default:
err(1, "Unknown option: %c\n", ch);
break;
}
}
printf("flag_a = %d\n", flag_a);
return (0);
}
void
sub(int flag)
{
printf("flag = %d\n", flag);
}
$ cc -g main.c
$ gdb a.out
GNU gdb 6.3
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "amd64-unknown-openbsd6.3"...
(gdb) b main
Breakpoint 1 at 0x56b: file main.c, line 11.
(gdb) run
Starting program: /home/asou/tmp/a.out
Breakpoint 1 at 0x12776150056b: file main.c, line 11.
Breakpoint 1, main (argc=1, argv=0x7f7ffffc3b08) at main.c:11
11 int flag_a = 0;
Current language: auto; currently minimal
(gdb) next
13 sub(1);
(gdb) next
flag = 1
0x0000127761500579 in main (argc=1, argv=0x7f7ffffc3b08)
from /home/asou/tmp/a.out
(gdb) next
Single stepping until exit from function main,
which has no line number information.
flag_a = 0
0x0000127761500436 in _start () from /home/asou/tmp/a.out
(gdb) bt
#0 0x0000127761500436 in _start () from /home/asou/tmp/a.out
#1 0x0000000000000000 in ?? ()
(gdb)
My patch as below:
$ git diff
diff --git a/gnu/usr.bin/binutils/gdb/dwarf2read.c
b/gnu/usr.bin/binutils/gdb/dwarf2read.c
index 96f9e0f8551..651904d763d 100644
--- a/gnu/usr.bin/binutils/gdb/dwarf2read.c
+++ b/gnu/usr.bin/binutils/gdb/dwarf2read.c
@@ -6479,7 +6479,11 @@ dwarf_decode_lines (struct line_header *lh, char
*comp_dir, bfd *abfd,
* lh->minimum_instruction_length;
line += lh->line_base + (adj_opcode % lh->line_range);
lh->file_names[file - 1].included_p = 1;
+#if 0 /* for debug by asou */
if (!decode_for_pst_p)
+#else /* for debug by asou */
+ if (line != 0 && !decode_for_pst_p)
+#endif /* for debug by asou */
{
/* Append row to matrix using current values. */
record_line (current_subfile, line,
--
ASOU Masato