After debugging for some hours, I am unable to debug my project I'm making anymore for the following reasons.
(It compiles smoothly without errors nor warnings from the compiler.)
Problem #1:
Error creating process d:\My
Documents\Downloads\CandyCrush\CandyCrush\bin\debug\CandyCrush.exe,
(error 5).
Solutions:
I followed the suggestions
here and here,
so I think it fixed one thing. ('spaces' in environment path)
Reboot the computer to ensure that the path is made available to all processes properly as suggested here. (Although its somewhat not really related to my problem)
Change the directory of my IDE along with the compiler.
Change the directory of the project I'm working on.
Delete and reinstall MinGW.
Delete and reinstall Code::Blocks.
And it changes the problem.
(take note that I always try to debug and run after each solutions)
Problem #2:
Starting debugger: D:\cb\CodeBlocks\MingGW\bin\gdb.exe -nx -fullname -quiet -args D:/CandyCrush/CandyCrush/bin/Debug/CandyCrush.exe failed
Solution:
Configure manually the path of debugger from the IDE (it says it can't find the file but it is there(?)) so it does fixed it.
Aaaand the first problem return again, so I think I really mess up things here.
What could be the fix?
PS. I'm using GNU gdb (GDB) 7.5
Edit
Full (Debug) log
Debugger name and version: GNU gdb (GDB) 7.5
[debug]>>>>>>cb_gdb: [debug]> set width 0 [debug]>>>>>>cb_gdb:
[debug]> set height 0 [debug]>>>>>>cb_gdb: [debug]> set breakpoint
pending on [debug]>>>>>>cb_gdb: [debug]> set print asm-demangle on
[debug]>>>>>>cb_gdb: [debug]> set unwindonsignal on
[debug]>>>>>>cb_gdb: [debug]> set print elements 0
[debug]>>>>>>cb_gdb: [debug]> set new-console on [debug]>>>>>>cb_gdb:
[debug]> set disassembly-flavor att [debug]>>>>>>cb_gdb: [debug]>
catch throw [debug]Catchpoint 1 (throw) [debug]>>>>>>cb_gdb: [debug]>
source D:\cb\CodeBlocks\share\codeblocks/scripts/stl-views-1.0.3.gdb
[debug]>>>>>>cb_gdb: [debug]> directory D:/CandyCrush/CandyCrush/
[debug]Source directories searched:
D:/CandyCrush/CandyCrush;$cdir;$cwd [debug]>>>>>>cb_gdb: [debug]> run
[debug]Error creating process
D:\CandyCrush\CandyCrush\bin\Debug\CandyCrush.exe, (error 5).
[debug]Starting program:
D:\CandyCrush\CandyCrush\bin\Debug\CandyCrush.exe
[debug]>>>>>>cb_gdb:
Error creating process
D:\CandyCrush\CandyCrush\bin\Debug\CandyCrush.exe, (error 5).
[debug]> quit
Debugger finished with status 0
This isn't good at all. After resting the IDE(compiler, debugger, editor) for some hours, it magically works again. I didn't close any application or reboot the computer.
Also It's because of Game Guard or Anti Virus
Related
gdb -quiet -iex 'set pagination off' -ex run -ex 'thread apply all bt' --batch --args <your prog>
The above is my default way or running my programs in CI. It is very convenient to have a stacktrace printed if the binary crashes, without having to hunt for coredump files.
edit: my default way of running CI has changed, because I also need to propagate the return code from the tested program in some circumstances
gdb -quiet -iex 'set pagination off' -iex 'set debuginfod enabled on' -ex run -ex 'thread apply all bt' -ex 'quit $_exitcode' --batch --args <your prog>
The problem is that I cannot do this when I compile with -fsanitize=address,leak,undefined. I get an error message when the program runs to the end and lsan is triggered (in an atexit handler, according to its docs).
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
==2861213==LeakSanitizer has encountered a fatal error.
==2861213==HINT: For debugging, try setting environment variable LSAN_OPTIONS=verbosity=1:log_threads=1
==2861213==HINT: LeakSanitizer does not work under ptrace (strace, gdb, etc)
[Inferior 1 (process 2861213) exited with code 01]
Q1: Can I maintain the convenience of my gdb -quiet setup, while still getting lsan leak reports when my program leaks?
Currently the solution I am implementing is to hunt for the coredump files and execute gdb on them in a subsequent CI step (that runs upon test failure). For this, I had to configure sanitizers to permit coredump generation with disable_coredump=0, as described in How to generate core dump when use Address Sanitizer and gcc7.1.0.
Q2: Is it possible to use AddressSanitizer to do the job gdb used to do for me? That is, to run the equivalent of bt or thread apply all bt when my program crashes?
export DEBUGINFOD_URLS=https://debuginfod.elfutils.org
gdb -quiet -iex 'set pagination off' -iex 'set debuginfod enabled on' -iex 'set detach-on-fork off' -iex 'set breakpoint pending on' -x gha_gdb_commandfile.txt --args <your prog> <args>
The gdb_commandfile.txt being
break __lsan::CheckForLeaks
commands
detach
end
run
thread apply all bt
thread apply all py-bt
The gdb command file breaks when leak sanitizer is starting and detaches the debugger, so that leak sanitizer is free to do its own attach.
I tried this to debug this main.c
#include <assert.h>
#include <stdlib.h>
int main(int argc, char** argv) {
void* x = malloc(42);
if (argc > 1) assert(1 == 2);
return 0;
}
compiled as
gcc -g3 -fsanitize=address,leak main.c
and it gives both leak report and backtrace, depending on whether I run with argument or not.
The command works even if binary is compiled without leak sanitizer. Then gdb simply never sets the breakpoint.
I wanted to have gdb watch both parent and child if my process starts a subprocess. I tried to use 'set detach-on-fork off' for it. I need it because there might be subprocesses that should be leak-checked (and stacktrace should be dumped if they crash). But what I tried is not the way. The parent process should instead start the child within new instance of GDB. By default, GDB continues attached to parent, ignoring the child.
The rr debugger is able to record entire process subtree. Maybe there can be a way. But that is for another question.
in my code, I have a break point set at line 8. the debugger doesn't stop there, but DOES stop at line 40. (which is an if-statement in a function definition, if that matters).
-g is on, -s is not, it's built to debug, the file path contains no strange characters.
debugger log:
Starting debugger: C:\MinGW\bin\gdb.exe -nx -fullname -quiet -args C:/Users/John/Desktop/programming/roguelike/bin/Debug/roguelike.exe
done
Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints
Debugger name and version: GNU gdb (GDB) 7.6.1
Child process PID: 9152
At C:\Users\John\Desktop\programming\roguelike\roguelikesource.cpp:40
pressing continue while it's stopped at 40 gives
Continuing...
In RaiseException () (C:\Windows\SysWOW64\KernelBase.dll)
and pressing it again causes a generic error popup and gives
Continuing...
[Inferior 1 (process 9152) exited with code 0377]
Debugger finished with status 0
I'm trying to debug my program using C::B and added to the compiler settings:
#define
-DNDEBEUG
I get the log:
[debug]> run
[debug]No executable specified, use `target exec'.
[debug]Starting program:
[debug]>>>>>>cb_gdb:
Starting the debugger failed: No executable specified, use `target exec'.
[debug]> quit
Debugger finished with status 0
anyone can help please?
Breakpoints may not work if the folder you've placed your application has spaces or other special characters. replacing space with Underscore _ may solve the issue.
Click here for addition details to debug application in Code::blocks
I have code blocks 13.12 with borland 5.5 and mingw debugger. Everytime I debug, it debugs it completely without stopping at breakpoints or cursor (when pressed run to cursor). The debug log is:
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: G:\Copy_string\
Adding source dir: G:\Copy_string\
Adding file: G:\Copy_string\bin\Debug\Copy_string.exe
Changing directory to: G:/Copy_string/.
Set variable: PATH=.;C:\Borland\BCC55\Bin;C:\Borland\BCC55;C:\Program Files\Intel\iCLS
Client;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\
WindowsPowerShell\v1.0;C:\Program Files\Intel\OpenCL SDK\2.0\bin\x86;C:\Program
Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management
Engine Components\IPT
[debug]Command-line: C:\CodeBlocks\MinGW\bin\gdb.exe -nx -fullname -quiet -args
G:/Copy_string/bin/Debug/Copy_string.exe
[debug]Working dir : G:\Copy_string
Starting debugger: C:\CodeBlocks\MinGW\bin\gdb.exe -nx -fullname -quiet -args
G:/Copy_string/bin/Debug/Copy_string.exe
done
[debug]> set prompt >>>>>>cb_gdb:
Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints
[debug]Reading symbols from G:\Copy_string\bin\Debug\Copy_string.exe...(no debugging symbols found)...done.
[debug](gdb) >>>>>>cb_gdb:
[debug]> show version
Reading symbols from G:\Copy_string\bin\Debug\Copy_string.exe...(no debugging symbols found)...done.
[debug]GNU gdb (GDB) 7.5
[debug]Copyright (C) 2012 Free Software Foundation, Inc.
[debug]License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
[debug]This is free software: you are free to change and redistribute it.
[debug]There is NO WARRANTY, to the extent permitted by law. Type "show copying"
[debug]and "show warranty" for details.
[debug]This GDB was configured as "i686-pc-mingw32".
[debug]For bug reporting instructions, please see:
[debug]<http://www.gnu.org/software/gdb/bugs/>.
[debug]>>>>>>cb_gdb:
[debug]> set confirm off
Debugger name and version: GNU gdb (GDB) 7.5
[debug]>>>>>>cb_gdb:
[debug]> set width 0
[debug]>>>>>>cb_gdb:
[debug]> set height 0
[debug]>>>>>>cb_gdb:
[debug]> set breakpoint pending on
[debug]>>>>>>cb_gdb:
[debug]> set print asm-demangle on
[debug]>>>>>>cb_gdb:
[debug]> set unwindonsignal on
[debug]>>>>>>cb_gdb:
[debug]> set print elements 0
[debug]>>>>>>cb_gdb:
[debug]> set new-console on
[debug]>>>>>>cb_gdb:
[debug]> set disassembly-flavor att
[debug]>>>>>>cb_gdb:
[debug]> catch throw
[debug]Function "__cxa_throw" not defined.
[debug]Catchpoint 1 (throw)
[debug]>>>>>>cb_gdb:
[debug]> source C:\CodeBlocks\share\codeblocks/scripts/stl-views-1.0.3.gdb
[debug]>>>>>>cb_gdb:
[debug]> set follow-fork-mode child
[debug]>>>>>>cb_gdb:
[debug]> directory G:/Copy_string/
[debug]Source directories searched: G:/Copy_string;$cdir;$cwd
[debug]>>>>>>cb_gdb:
[debug]> run
[debug]Starting program: G:\Copy_string\bin\Debug\Copy_string.exe
Child process PID: 3596
[debug][New Thread 3596.0x4e4]
[debug][Inferior 1 (process 3596) exited with code 020325214]
[debug]>>>>>>cb_gdb:
[Inferior 1 (process 3596) exited with code 020325214]
[debug]> quit
Debugger finished with status 0
`
Make sure that 'Build->Select target' is [X] Debug. Then open the source program you want to debug and click on the line where you want the debugger to stop.
Lastly, use [Right Click]+[Run to cursor]. A yellow arrow should show besides the line number on your source code window.
This worked with me:
choose debugger from setting.
select default
change the executable path to
C:\msys64\mingw64\bin\gdb.exe
I use gdb and gdbserver on target, remote debug success in shell, ti's ccs5 and codesourery,but when i try the eclipse to do the ssme thing, it fail.
"Failed to execute MI command"
"help maintenance set"
(gdb) help maintenance set
Set GDB internal variables used by the GDB maintainer.
Configure variables internal to GDB that aid in GDB's maintenance
List of maintenance set subcommands:
maintenance set dwarf2 -- Set DWARF 2 specific variables
maintenance set internal-error -- Configure what GDB does when internal-error is detected
maintenance set internal-warning -- Configure what GDB does when internal-warning is detected
maintenance set profile -- Set internal profiling
Log:
Error in final launch sequence
Failed to execute MI command:
maintenance set python print-stack off
Error message from debugger back end:
Undefined maintenance set command: "python print-stack off". Try "help maintenance set".