Bug 21873 - GDB Crashes when ^C pressed while debugging ARM-Cortex M4F
Summary: GDB Crashes when ^C pressed while debugging ARM-Cortex M4F
Status: RESOLVED OBSOLETE
Alias: None
Product: gdb
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.4
: P1 critical
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-07-31 20:03 UTC by Ismail
Modified: 2023-12-07 13:49 UTC (History)
4 users (show)

See Also:
Host: Ubuntu 16.04
Target:
Build:
Last reconfirmed: 2023-10-05 00:00:00


Attachments
Core file that has crash info (1.20 MB, application/x-core)
2017-07-31 20:03 UTC, Ismail
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ismail 2017-07-31 20:03:52 UTC
Created attachment 10297 [details]
Core file that has crash info

I am debugging my firmware on MAX32630FTHR target using openocd server. While running the firmware, i hit the Ctrl+C keystore to be stop the firmware and enable command line in TUI mode. It crashes suddenly after the key pressing. I am running it on Ubuntu 16.04.

The target links are here.
https://www.maximintegrated.com/en/products/digital/microcontrollers/MAX32630FTHR.html
https://developer.mbed.org/platforms/MAX32630FTHR/


My gdbinit content are here.

define connect
        set trace-commands on
        set remotetimeout 1000000000
        set logging on
        target remote localhost:3333
end

define reset
        monitor reset halt
        c
end

define settings
        # set unlimited string size while print
        set print elements 0
end

define program
        monitor reset halt
        load build/output.elf
        monitor reset halt
end

define run_openocd
        target remote | openocd scripts/jtag/max3263x_hdk.cfg -c "gdb_port pipe; log_output ./openocd.log"
end

connect
settings
program
c
Comment 1 Ismail 2017-07-31 20:06:40 UTC
Here is the  arm-none-eabi-gdb -version command output.

GNU gdb (GNU Tools for ARM Embedded Processors) 7.4.1.20130913-cvs
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-linux-gnu --target=arm-none-eabi".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Comment 2 Ismail 2017-07-31 20:07:03 UTC
Here is the  arm-none-eabi-gdb -version command output.

GNU gdb (GNU Tools for ARM Embedded Processors) 7.4.1.20130913-cvs
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-linux-gnu --target=arm-none-eabi".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Comment 3 Ismail 2017-07-31 21:17:25 UTC
 5154 segmentation fault (core dumped)  arm-none-eabi-gdb -tui ./build/output.elf -x scripts/gdb/max32630.gdb
Comment 4 Yao Qi 2017-08-01 14:55:47 UTC
GDB 7.4.1 is too old.  Could you please try GDB 8.0, and build it from source?  If the crash is still there, use your host gdb to debug arm-none-eabi gdb, and show the stack backtrace of crash.  That will be very helpful to triage the issue.

$ mkdir build-gdb
$ cd build-gdb
$ ../binutils-gdb/configure --target=arm-none-eabi --disable-binutils --disable-ld --disable-gold --disable-gprof
$ make

then you can use ./gdb/gdb.
Comment 5 Ismail 2017-08-01 19:32:51 UTC
I downloaded gdb from the following read only repository and configure it with your parameters and then built it. GDB 8


git clone git://sourceware.org/git/binutils-gdb.git

Here is the GDB version output

$ gdb/gdb --version                                                                                                                                                     
GNU gdb (GDB) 8.0.50.20170801-git
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-pc-linux-gnu --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".



I dont know if generated bin files has issues. I use the following gcc compiler version. I sometimes see dwarf errors. But, the firmware itself works well.

arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 4.7.4 20130913 (release) [ARM/embedded-4_7-branch revision 202601]
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.



I am not sure how to debug the gdb itself. It seems little bit complicated. I have to use openocd in order to run and debug the program on the target. 

I will have one GDB as runner and debugger, the second one that works in TUI mode will connect to openocd and debug the firmware. 

I would be happy if you can give me some documents/guidance to debug it.

Thanks
Ismail
Comment 6 Yao Qi 2017-08-01 21:25:00 UTC
(In reply to Ismail from comment #5)
> 
> I am not sure how to debug the gdb itself. It seems little bit complicated.
> I have to use openocd in order to run and debug the program on the target. 
> 
> I will have one GDB as runner and debugger, the second one that works in TUI
> mode will connect to openocd and debug the firmware. 
> 
> I would be happy if you can give me some documents/guidance to debug it.

Use the built GDB as usual.  Start it in TUI mode, and connect to OpenOCD.  Start a new terminal, check the pid of the arm-none-eabi-gdb, like,

$ ps -elf | grep gdb

then start your host GDB (shipped in your distro) to attach the arm-none-eabi-gdb, like

$ gdb -p PID
 (gdb) continue

and then go back the first terminal (using arm-none-eabi-gdb in TUI mode).  Continue use it to reproduce the crash.  If it crashes, the host GDB will catch the SIGSEGV signal, and you can show the stack backtrace of crash, and examine why it crashes.
Comment 7 Ismail 2017-08-01 21:49:23 UTC
I did that works to start debugging the GDB. But, the only problem is when I attach the GDB that will be debugged does not responses to anything including Ctrl+C keystrokes. The other debugger GDB gets stop. In order to continue, i need to go to the other terminal and continue. That's weird.
Comment 8 Yao Qi 2017-08-02 07:44:22 UTC
(In reply to Ismail from comment #7)
> I did that works to start debugging the GDB. But, the only problem is when I
> attach the GDB that will be debugged does not responses to anything
> including Ctrl+C keystrokes. The other debugger GDB gets stop. In order to
> continue, i need to go to the other terminal and continue. That's weird.

Maybe it is easier to get coredump.  If you don't debug arm-none-eabi-gdb, does it still crash?  If it does, you can get the coredump, and then, start your host gdb like this,

$ gdb ./gdb ./core

and gdb command "bt" can tell us why gdb is crashed.
Comment 9 Ismail 2017-08-02 22:33:59 UTC
Here is the backtrace output. Hopefully, It may be helpful to locate the bug.

Thanks

(gdb) bt
#0  strlen () at ../sysdeps/x86_64/strlen.S:106
#1  0x000000000061222b in find_and_open_source (filename=0x20c <error: Cannot access memory at address 0x20c>, dirname=0x303078302829745f <error: Cannot access memory at address 0x303078302829745f>,
    fullname=fullname@entry=0x2912d28) at ../../binutils-gdb/gdb/source.c:1098
#2  0x000000000061235c in symtab_to_fullname (s=0x2912cf0) at ../../binutils-gdb/gdb/source.c:1167
#3  0x0000000000477b44 in tui_update_breakpoint_info (win=win@entry=0x2539a90, current_only=current_only@entry=0) at ../../binutils-gdb/gdb/tui/tui-winsource.c:461
#4  0x000000000047816b in tui_update_source_window_as_is (win_info=0x2539a90, gdbarch=gdbarch@entry=0x271f920, s=s@entry=0x25cf840, line_or_addr=..., noerror=noerror@entry=0)
    at ../../binutils-gdb/gdb/tui/tui-winsource.c:107
#5  0x0000000000474147 in tui_show_symtab_source (gdbarch=gdbarch@entry=0x271f920, s=s@entry=0x25cf840, line=..., noerror=noerror@entry=0) at ../../binutils-gdb/gdb/tui/tui-source.c:328
#6  0x0000000000477f63 in tui_update_source_windows_with_addr (gdbarch=0x271f920, addr=79676) at ../../binutils-gdb/gdb/tui/tui-winsource.c:156
#7  0x000000000047801a in tui_display_main () at ../../binutils-gdb/gdb/tui/tui-winsource.c:56
#8  0x00000000005dd80d in generic_observer_notify (args=0x7ffd6a7b4270, subject=<optimized out>) at ../../binutils-gdb/gdb/observer.c:167
#9  observer_notify_new_objfile (objfile=objfile@entry=0x0) at ./observer.inc:582
#10 0x0000000000621d1e in clear_symtab_users (add_flags=..., add_flags@entry=...) at ../../binutils-gdb/gdb/symfile.c:2957
#11 0x0000000000624807 in reread_symbols () at ../../binutils-gdb/gdb/symfile.c:2694
#12 0x0000000000624a02 in load_command (arg=0x0, from_tty=1) at ../../binutils-gdb/gdb/symfile.c:1835
#13 0x00000000004589f9 in cmd_func (cmd=<optimized out>, args=<optimized out>, from_tty=<optimized out>) at ../../binutils-gdb/gdb/cli/cli-decode.c:1902
#14 0x0000000000650c70 in execute_command (p=<optimized out>, p@entry=0x2539730 "", from_tty=1) at ../../binutils-gdb/gdb/top.c:675
#15 0x000000000057247c in command_handler (command=0x2539730 "") at ../../binutils-gdb/gdb/event-top.c:590
#16 0x0000000000572798 in command_line_handler (rl=<optimized out>) at ../../binutils-gdb/gdb/event-top.c:780
#17 0x0000000000571a2c in gdb_rl_callback_handler (rl=0x254be30 "") at ../../binutils-gdb/gdb/event-top.c:213
#18 0x00000000006d06e3 in rl_callback_read_char () at ../../binutils-gdb/readline/callback.c:220
#19 0x000000000057195e in gdb_rl_callback_read_char_wrapper_noexcept () at ../../binutils-gdb/gdb/event-top.c:175
#20 0x00000000005719d9 in gdb_rl_callback_read_char_wrapper (client_data=<optimized out>) at ../../binutils-gdb/gdb/event-top.c:192
#21 0x0000000000571f60 in stdin_event_handler (error=<optimized out>, client_data=0x2340df0) at ../../binutils-gdb/gdb/event-top.c:518
#22 0x0000000000570d5d in gdb_wait_for_event (block=block@entry=1) at ../../binutils-gdb/gdb/event-loop.c:859
#23 0x0000000000570eb2 in gdb_do_one_event () at ../../binutils-gdb/gdb/event-loop.c:347
#24 0x000000000057100e in gdb_do_one_event () at ../../binutils-gdb/gdb/event-loop.c:304
#25 start_event_loop () at ../../binutils-gdb/gdb/event-loop.c:371
#26 0x00000000005c8038 in captured_command_loop (data=data@entry=0x0) at ../../binutils-gdb/gdb/main.c:325
#27 0x00000000005730e3 in catch_errors (func=func@entry=0x5c8010 <captured_command_loop(void*)>, func_args=func_args@entry=0x0, errstring=errstring@entry=0x80c1b0 "", mask=mask@entry=RETURN_MASK_ALL)
    at ../../binutils-gdb/gdb/exceptions.c:236
#28 0x00000000005c8ef6 in captured_main (data=0x7ffd6a7b47b0) at ../../binutils-gdb/gdb/main.c:1150
#29 gdb_main (args=args@entry=0x7ffd6a7b48f0) at ../../binutils-gdb/gdb/main.c:1160
#30 0x000000000040e015 in main (argc=<optimized out>, argv=<optimized out>) at ../../binutils-gdb/gdb/gdb.c:32
Comment 10 Ismail 2017-08-02 22:40:17 UTC
   │1030                                                                                                            │
   │1031    int                                                                                                     │
   │1032    find_and_open_source (const char *filename,                                                             │
   │1033                          const char *dirname,                                                              │
   │1034                          char **fullname)                                                                  │
   │1035    {                                                                                                       │


.............

   ┌──../../binutils-gdb/gdb/source.c──────────────────────────────────────────────────────
   │1052              xfree (*fullname);                                                   
   │1053              *fullname = rewritten_fullname;                                      
   │1054            }                                                                      
   │1055                                                                                   
   │1056          result = gdb_open_cloexec (*fullname, OPEN_MODE, 0);                     
   │1057          if (result >= 0)                                                         
   │1058            {                                                                      
   │1059              char *lpath = gdb_realpath (*fullname);                              
   │1060                                                                                   
   │1061              xfree (*fullname);                                                   
   │1062              *fullname = lpath;                                                   
   │1063              return result;                                                       
   │1064            }                                                                      
   │1065                                                                                   
   │1066          /* Didn't work -- free old one, try again.  */                           
   │1067          xfree (*fullname);                                                       
   │1068          *fullname = NULL;                                                        
   │1069        }                                                                          
   │1070                                                                                   
   │1071      cleanup = make_cleanup (null_cleanup, NULL);                                 
   │1072                                                                                   
   │1073      if (dirname != NULL)                                                         
   │1074        {                                                                          
   │1075          /* If necessary, rewrite the compilation directory name according        
   │1076             to the source path substitution rules specified by the user.  */      
   │1077                                                                                   
   │1078          char *rewritten_dirname = rewrite_source_path (dirname);                 
   │1079                                                                                   
   │1080          if (rewritten_dirname != NULL)                                           
   │1081            {                                                                      
   │1082              make_cleanup (xfree, rewritten_dirname);                             
   │1083              dirname = rewritten_dirname;                                         
   │1084            }                                                                      
   │1085                                                                                   
   │1086          /* Replace a path entry of $cdir with the compilation directory          
   │1087             name.  */                                                             
   │1088    #define cdir_len        5                                                      
   │1089          /* We cast strstr's result in case an ANSIhole has made it const,        
   │1090             which produces a "required warning" when assigned to a nonconst.  */  
   │1091          p = (char *) strstr (source_path, "$cdir");                              
   │1092          if (p && (p == path || p[-1] == DIRNAME_SEPARATOR)                       
   │1093              && (p[cdir_len] == DIRNAME_SEPARATOR || p[cdir_len] == '\0'))        
   │1094            {                                                                      
   │1095              int len;                                                             
   │1096                                                                                   
   │1097              path = (char *)                                                      
  >│1098                alloca (strlen (source_path) + 1 + strlen (dirname) + 1);      /*CRASHES HERE */    
   │1099              len = p - source_path;                                               
   │1100              strncpy (path, source_path, len);     /* Before $cdir */             
   │1101              strcpy (path + len, dirname);         /* new stuff */                
   │1102              strcat (path + len, source_path + len + cdir_len);    /* After       
   │1103                                                                       $cdir */    
   │1104            }                                                                      
   │1105        }                                                                          
   └───────────────────────────────────────────────────────────────────────────────────────
multi-thre Thread 0x7f03cf6957 In: find_and_open_source                                    
#20 0x00000000005719d9 in gdb_rl_callback_read_char_wrapper (client_
#21 0x0000000000571f60 in stdin_event_handler (error=<optimized out>
#22 0x0000000000570d5d in gdb_wait_for_event (block=block@entry=1) a
#23 0x0000000000570eb2 in gdb_do_one_event () at ../../binutils-gdb/
#24 0x000000000057100e in gdb_do_one_event () at ../../binutils-gdb/
#25 start_event_loop () at ../../binutils-gdb/gdb/event-loop.c:371
#26 0x00000000005c8038 in captured_command_loop (data=data@entry=0x0
#27 0x00000000005730e3 in catch_errors (func=func@entry=0x5c8010 <ca
    at ../../binutils-gdb/gdb/exceptions.c:236
#28 0x00000000005c8ef6 in captured_main (data=0x7ffd6a7b47b0) at ../
---Type <return> to continue, or q <return> to quit---
#29 gdb_main (args=args@entry=0x7ffd6a7b48f0) at ../../binutils-gdb/
#30 0x000000000040e015 in main (argc=<optimized out>, argv=<optimize
(gdb) up
#1  0x000000000061222b in find_and_open_source (filename=0x20c <erro
    fullname=fullname@entry=0x2912d28) at ../../binutils-gdb/gdb/sou
(gdb) p source_path
$1 = 0x23c36e0 "$cdir:$cwd"
(gdb) p dirname
$2 = 0x303078302829745f <error: Cannot access memory at address 0x30
(gdb)
Comment 11 Ismail 2017-08-02 22:49:28 UTC
Let me try to debug the issue. Perhaps I may figure out the issue and send a patch.
Comment 12 Yao Qi 2017-08-09 08:17:53 UTC
(In reply to Ismail from comment #11)
> Let me try to debug the issue. Perhaps I may figure out the issue and send a
> patch.

dirname points to a garbage address.  valgrind or address sanitizer is good at finding such problems, you can either

 1) run arm-none-eabi-gdb with valgrind, like 'valgrind ./gdb/gdb',
 2) or rebuild gdb with address sanitizer, $ make CXXFLAGS="-O0 -g3 -fsanitize=address" gdb
Comment 13 Tom Tromey 2023-10-05 16:33:22 UTC
Is this still a problem?
Comment 14 Luis Machado 2023-12-07 13:25:41 UTC
Judging by the silence, I don't think so.
Comment 15 Tom Tromey 2023-12-07 13:49:13 UTC
Please reopen or comment if this is still an issue.
Meanwhile, closing.