gdb Don't know how to run target in cross-compiler environment - c++

I want to debug gtest ut exec file. but it failed to use aarch64-poky-linux-gdb run.
my host is x86 environment, and my compile environment is arm64.
This GDB was configured as "--host=x86_64-pokysdk-linux --target=aarch64-poky-linux".
I used this cmd to run
$ aarch64-poky-linux-gdb --args ./unittests/ut_settings --gtest_filter=SettingsTestSuite.testParseStatus
$ file ut_settings
ut_settings: ELF 64-bit LSB shared object, ARM aarch64, version 1 (GNU/Linux), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, BuildID[sha1]=cb6d795bd316fb829ddd26caf317240532105469, for GNU/Linux 3.14.0, with debug_info, not stripped
but when i typed run, it cannot run
(gdb) r
Don't know how to run. Try "help target".
but is use ctest it can run, so i guess it can be use gdb debug, but i don't know how to. can some one help me how to run it
the entire log
$ aarch64-poky-linux-gdb --args ./unittests/ut_settings --gtest_filter=SettingsTestSuite.testParseStatus
GNU gdb (GDB) 9.1
Copyright (C) 2020 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-pokysdk-linux --target=aarch64-poky-linux".
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"...
Reading symbols from ./unittests/ut_settings...
(gdb) r
Don't know how to run. Try "help target".
(gdb) help target
Connect to a target machine or process.
The first argument is the type or protocol of the target machine.
Remaining arguments are interpreted by the target protocol. For more
information on the arguments for a particular protocol, type
`help target ' followed by the protocol name.
List of target subcommands:
target core -- Use a core file as a target.
target exec -- Use an executable file as a target.
target extended-remote -- Use a remote computer via a serial line, using a gdb-specific protocol.
target record-btrace -- Collect control-flow trace and provide the execution history.
target record-core -- Log program while executing and replay execution from log.
target record-full -- Log program while executing and replay execution from log.
target remote -- Use a remote computer via a serial line, using a gdb-specific protocol.
target tfile -- Use a trace file as a target.
Type "help target" followed by target subcommand name for full documentation.
Type "apropos word" to search for commands related to "word".
Type "apropos -v word" for full documentation of commands related to "word".
Command name abbreviations are allowed if unambiguous.

Related

GDB STM32 Clion flash but no debug

I have successfully set up gdb to debug stm32 on Clion.
However, it's only able to flash the .elf on to the target, Clion exits the debugging mode immediately when the flashing is done.
I would like of course to have the ability to properly debug using breakpoints, etc
Here are the debugging properties :
I believe I should put something in target remote args and that all my problem arise from here. I've tested with target extended-remote \\.\COM5 but it ended with a failure
Content of the args file :
target extended-remote \\.\COM5
monitor swdp_scan
attach 1
load
set mem inaccessible-by-default off
run
Here is the Clion console :
arm-none-eabi-gdb.exe cmake-build-debug\EPUCK2Test.elf --interpreter=mi --command=cmake-build-debug\args
=thread-group-added,id="i1"
~"GNU gdb (GNU Tools for Arm Embedded Processors 7-2017-q4-major) 8.0.50.2017112
8-git\n"
~"Copyright (C) 2017 Free Software Foundation, Inc.\n"
~"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\
nThis is free software: you are free to change and redistribute it.\nThere is NO
WARRANTY, to the extent permitted by law. Type \"show copying\"\nand \"show wa
rranty\" for details.\n"
~"This GDB was configured as \"--host=i686-w64-mingw32 --target=arm-none-eabi\".
\nType \"show configuration\" for configuration details."
~"\nFor bug reporting instructions, please see:\n"
~"<http://www.gnu.org/software/gdb/bugs/>.\n"
~"Find the GDB manual and other documentation resources online at:\n<http://www.
gnu.org/software/gdb/documentation/>.\n"
~"For help, type \"help\".\n"
~"Type \"apropos word\" to search for commands related to \"word\"...\n"
~"Reading symbols from cmake-build-debug\\EPUCK2Test.elf..."
~"done.\n"
#"Target voltage: ABSENT!\n"
#"Available Targets:\n"
#"No. Att Driver\n"
#" 1 STM32F40x M3/M4\n"
=thread-group-started,id="i1",pid="1"
=thread-created,id="1",group-id="i1"
~"HAL_GetTick () at D:/Data/Dev/Minor/STM32/EPUCK2Test/Drivers/STM32F4xx_HAL_Dri
ver/Src/stm32f4xx_hal.c:326\n"
~"326\t}\n"
*stopped,frame={addr="0x08000744",func="HAL_GetTick",args=[],file="D:/Data/Dev/M
inor/STM32/EPUCK2Test/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c",fullname
="D:\\Data\\Dev\\Minor\\STM32\\EPUCK2Test\\Drivers\\STM32F4xx_HAL_Driver\\Src\\s
tm32f4xx_hal.c",line="326"},thread-id="1",stopped-threads="all"
+download,{section=".isr_vector",section-size="392",total-size="49699"}
+download,{section=".isr_vector",section-sent="392",section-size="392",total-sen
t="392",total-size="49699"}
+download,{section=".text",section-size="4264",total-size="49699"}
+download,{section=".rodata",section-size="20",total-size="49699"}
+download,{section=".ARM",section-size="8",total-size="49699"}
+download,{section=".init_array",section-size="8",total-size="49699"}
+download,{section=".fini_array",section-size="4",total-size="49699"}
+download,{section=".data",section-size="1084",total-size="49699"}
=cmd-param-changed,param="mem inaccessible-by-default",value="off"
=thread-exited,id="1",group-id="i1"
=thread-group-exited,id="i1"
=thread-group-started,id="i1",pid="42000"
=thread-created,id="1",group-id="i1"
*running,thread-id="all"
com.jetbrains.cidr.execution.debugger.backend.gdb.GDBDriver$GDBCommandException: To open a remote debug connection, you need to specify what
serial device is attached to the remote system
(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).
Debugger disconnected
Process finished with exit code 0
GDB Server stopped, exit code 1
The end of the log is quite odd, it looks like for some reason gdb has been disconnected from the target
com.jetbrains.cidr.execution.debugger.backend.gdb.GDBDriver$GDBCommandException: To open a remote debug connection, you need to specify what
serial device is attached to the remote system
(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).
Debugger disconnected
What is even stranger is that there is no such "disconnection" when running the very same command arm-none-eabi-gdb.exe cmake-build-debug\EPUCK2Test.elf --interpreter=mi --command=cmake-build-debug\args directly in the terminal.
Thanks in advance for your help
The problem you are seeing is probably related to https://sourceware.org/bugzilla/show_bug.cgi?id=28711

My gdb debugger isn't responding when I launch it

I tried to setup the gdb debugger today which was already a hassle in itself. Now that it works (I can launch it at least) it gets stuck none of my commands have any effect on the debugger. I launch the debugger like so:
$ g++ main.cpp -g
$ gdb ./a.out
I can run layout next when I type run it just doesn't respond anymore.
I put an infinite loop in my program on purpose to see simulate a bug. Even without the loop its the exact same behavior.
It also doesn't say "done" when reading in the compiled file:
Now when I try to start gdb without any files specified. This is what happens:
➜ gdb
GNU gdb (GDB) 10.1
Copyright (C) 2020 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 "x86_64-apple-darwin20.1.0".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://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".
(gdb) file ./a.out
Reading symbols from ./a.out...
Reading symbols from /Users/Documents/coding/C++/testing_c++/testing_c++/a.out.dSYM/Contents/Resources/DWARF/a.out...
../../gdb/thread.c:95: internal-error: struct thread_info *inferior_thread(): Assertion `current_thread_ != nullptr' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) y
This is a bug, please report it. For instructions, see:
<https://www.gnu.org/software/gdb/bugs/>.
../../gdb/thread.c:95: internal-error: struct thread_info *inferior_thread(): Assertion `current_thread_ != nullptr' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Create a core file of GDB? (y or n) n

schedBreak(<tick>) gdb debugging function not working

I am trying to create breakpoints and debug gem5 using gdb. I referred to http://www.gem5.org/Debugger_Based_Debugging.
As in the official documentation in the above link, I tried `call schedBreak() but it doesn't work. the following are the full commands:
➜ test-gem5-x86 git:(master) ✗ gdb --args ./build/X86/gem5.opt configs/learning_gem5/part1/simple.py
GNU gdb (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-git
Copyright (C) 2018 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 "x86_64-linux-gnu".
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"...
Reading symbols from ./build/X86/gem5.opt...done.
(gdb) b main
Breakpoint 1 at 0x4b0d20: main. (4 locations)
(gdb) run
Starting program: /home/hari/test-gem5-x86/build/X86/gem5.opt configs/learning_gem5/part1/simple.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Breakpoint 1, main (argc=2, argv=0x7fffffffdef8) at build/X86/sim/main.cc:42
42 {
(gdb) call schedBreak(10000)
warn: need to stop all queues
(gdb) c
Continuing.
gem5 Simulator System. http://gem5.org
gem5 is copyrighted software; use the --copyright option for details.
gem5 compiled Aug 26 2019 20:59:02
gem5 started Sep 8 2019 15:17:55
gem5 executing on nirmal-cadsl2, pid 30158
command line: /home/hari/test-gem5-x86/build/X86/gem5.opt configs/learning_gem5/part1/simple.py
Global frequency set at 1000000000000 ticks per second
warn: DRAM device capacity (8192 Mbytes) does not match the address range assigned (512 Mbytes)
0: system.remote_gdb: listening for remote gdb on port 7001
Beginning simulation!
info: Entering event queue # 0. Starting simulation...
Hello world!
Exiting # tick 501393000 because exiting with last active thread context
[Inferior 1 (process 30158) exited normally]
(gdb)
While this other tutorial http://gem5.org/wiki/images/0/0e/ASPLOS2017_gem5_tutorial.pdf (assuming the debug function is not particular to ISA) tells me that the function is actually schedBreakCycle(), it gives me this No symbol "schedBreakCycle" in current context. The full commands shown below.
➜ test-gem5-x86 git:(master) ✗ gdb --args ./build/X86/gem5.opt configs/learning_gem5/part1/simple.py
GNU gdb (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-git
Copyright (C) 2018 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 "x86_64-linux-gnu".
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"...
Reading symbols from ./build/X86/gem5.opt...done.
(gdb) b main
Breakpoint 1 at 0x4b0d20: main. (4 locations)
(gdb) run
Starting program: /home/hari/test-gem5-x86/build/X86/gem5.opt configs/learning_gem5/part1/simple.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Breakpoint 1, main (argc=2, argv=0x7fffffffdef8) at build/X86/sim/main.cc:42
42 {
(gdb) call schedBreakCycle(10000)
No symbol "schedBreakCycle" in current context.
(gdb)
gem5 version: ea8c435b6c6c092d72047eee50f125f5ae7347c3
gdb version: GNU gdb (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-git
Also, if I want to debug ALPHA or ARM full system on my ubuntu 18.04(x86), do I have to use any cross-compiled gdb versions or would native gdb suffice?
The tutorial is correct, you have to pass --debug-break to gem5:
gdb --args gem5.debug --debug-break=1000 ...
and then without breaking at main:
run
call schedBreak(5000)
continue
--debug-break generates a break at time 1000 and makes GDB stop there after main, and from that point, schedBreak does work.
Or alternatively first go to:
tbreak doSimLoop
run
call schedBreak(5000)
continue
schedBreak schedules an event in the event queue, which cannot be ready at main.
The breaks work by raising a signal, which GDB stops at by default.
ALPHA and ARM won't make a difference since schedBreak is a tiny helper to debug the host emulator itself, which is likely an x86 program. To debug the guest code, which is what most people want, see e.g. this tutorial.
Tested gem5 master at e87a293d1ffa6da38ba8fa145e7dc5128138ab77 in an X86 debug build.

"No such file or directory" messages when using GDB with C++ programs

I'm pretty new to using GDB, so sorry if this is a noob question.
When using GDB on any C++ program, I get a large number of "No such file or directory" messages. This does not happen with C programs.
Here's what I'm doing:
$ g++ -g hello-world.cpp -o hello-world.o
$ gdb hello-world.o
GNU gdb (GDB) 7.11.1
Copyright (C) 2016 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 "x86_64-apple-darwin15.5.0".
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"...
Reading symbols from hello-world.o...Reading symbols from /Users/noah/c++/hello-world.o.dSYM/Contents/Resources/DWARF/hello-world.o...done.
done.
(gdb) r
Starting program: /Users/noah/c++/hello-world.o
warning: `/private/tmp/gcc6-20160515-25034-1nu0tpk/gcc-6.1.0/build/x86_64-apple-darwin15.2.0/libstdc++-v3/src/.libs/compatibility-atomic-c++0x.o': can't open to read symbols: No such file or directory.
warning: `/private/tmp/gcc6-20160515-25034-1nu0tpk/gcc-6.1.0/build/x86_64-apple-darwin15.2.0/libstdc++-v3/src/.libs/compatibility-c++0x.o': can't open to read symbols: No such file or directory.
warning: `/private/tmp/gcc6-20160515-25034-1nu0tpk/gcc-6.1.0/build/x86_64-apple-darwin15.2.0/libstdc++-v3/src/.libs/compatibility-chrono.o': can't open to read symbols: No such file or directory.
(many more messages omitted)
warning: `/private/tmp/gcc6-20160515-25034-1nu0tpk/gcc-6.1.0/build/x86_64-apple-darwin15.2.0/libgcc/unordtf2_s.o': can't open to read symbols: No such file or directory.
warning: `/private/tmp/gcc6-20160515-25034-1nu0tpk/gcc-6.1.0/build/x86_64-apple-darwin15.2.0/libgcc/unwind-c_s.o': can't open to read symbols: No such file or directory.
warning: `/private/tmp/gcc6-20160515-25034-1nu0tpk/gcc-6.1.0/build/x86_64-apple-darwin15.2.0/libgcc/unwind-dw2_s.o': can't open to read symbols: No such file or directory.
Hello World
[Inferior 1 (process 2319) exited normally]
(gdb)
I'm using OS X El Capitan, with G++ 6.1.0 and GDB 7.11.1, both installed through Homebrew. GDB is codesigned using these instructions.

gdb in emacs hangs when issuing the 'q(uit)' command

I'm using emacs 24.5.1 under Mac Yosemite, in graphical mode and I'm trying to get gdb 7.11 working.
After starting gdb with 'gdb', I use 'r' to run a mini C++ code, consisting only of an empty main(), which exits normally. After it exits I can type 'r' again and the program will run and exit fine again. However, when I type 'q' to quit gdb, I get a newline without the (gdb) prompt, but gdb does not seem to have quit; It no longer responds to input, but when I try invoking gdb again, emacs tells me that 'this program is already being debugged'.
Current directory is ~/cpp/ppcpp/
GNU gdb (GDB) 7.11
Copyright (C) 2016 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 "x86_64-apple-darwin15.4.0".
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"...
Reading symbols from a.out...Reading symbols from /Users/mwisse/cpp/ppcpp/a.out.dSYM/Contents/Resources/DWARF/a.out...done.
done.
(gdb) r
Starting program: /Users/mwisse/cpp/ppcpp/a.out
[Inferior 1 (process 98675) exited normally]
(gdb) r
Starting program: /Users/mwisse/cpp/ppcpp/a.out
[Inferior 1 (process 98677) exited normally]
(gdb) q
...This is me typing something to show I can type anything here...
but no response.
Has anyone seen this before?
I didn't find out what caused the issue, but it went away after replacing my .emacs.d directory with the one mentioned here: http://tuhdo.github.io/emacs-for-proglang.html.