XCode Compiling - c++

When I compile my XCode Code I get this at the bottom...Im not sure whats wrong?...I am coding in C++
GNU gdb 6.3.50-20050815 (Apple version
gdb-1518) (Sat Feb 12 02:52:12 UTC
2011) 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
"x86_64-apple-darwin".tty /dev/ttys000
sharedlibrary apply-load-rules all
[Switching to process 2627 thread 0x0]
(gdb)
here is my code
#include <iostream>
#include <cmath>
int main ()
{
using namespace std;
double num1;
num1 = pow (2.0,4.0);
cout << num1 << endl;
system("pause");
return 0;
}

At a guess:
system("pause");
causes the problem, as OS X may not have a "pause" command.

That is some logging generated by the debugger, nothing to worry about.
The debugger is a process you can use to monitor your application at run time, if you haven't done any code optimization during compilation you can even change your code while your app is running.
If you don't want the debugger you can turn it off by changing the scheme in xcode.
Also the "pause" command does not ship with os X by default, is it something you made?

Related

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

Xcode and C++ [Beginner] - Why is the Hello World program printing all this extra stuff?

Whenever I build+run my program, it displays all this extra stuff:
GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Thu Nov 3 21:59:02
UTC 2011) 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 "x86_64-apple-darwin".tty /dev/ttys000
[Switching to process 3022 thread 0x0]
Hello, World!
Program endedwith exit code: 0
Here is the Hello World, default code:
#include <iostream>
int main (int argc, const char * argv[])
{
// insert code here...
std::cout << "Hello, World!\n";
return 0;
}
Why is it printing all the extra stuff, and how can I stop it? I'm using Xcode and C++. Thanks.
It's printing all of that extra stuff because it's running your executable in the debugger. You can change the popup from All Output to just "Target Output" like shown in the images below:
Build the app and then run it from the command line (in Terminal) and you won't see any of that GDB stuff.
If you want to do debugging though, you'll see (and eventually come to ignore) those extra lines.
Checking really quickly, I see that Apple's newer debugger (LLDB) prints out significantly less "extra" stuff into XCode's debugging output/console.
gdb is the GNU debugger. Running in the IDE that way seems to default to running under the debugger. In short it has nothing to do with your code and everything to do with the environment you are using.

gdb cannot step into printf

here is my sample program:
#include<stdio.h>
int main()
{
printf("hello good morning \n");
return 0;
}
gcc -Wall -g temp.c
/opt/langtools/bin/gdb a.out
HP gdb 3.3 for PA-RISC 1.1 or 2.0 (narrow), HP-UX 11.00.
Copyright 1986 - 2001 Free Software Foundation, Inc.
Hewlett-Packard Wildebeest 3.3 (based on GDB) is covered by the
GNU General Public License. Type "show copying" to see the conditions to
change it and/or distribute copies. Type "show warranty" for warranty/support.
..
(gdb) b 6
Breakpoint 1 at 0x2b14: file temp.c, line 6.
(gdb) run
Starting program: /oo_dgfqausr/test/dfqwrk4/temp/a.out
Breakpoint 1, main () at temp.c:6
6 printf("hello good morning \n");
(gdb) step
hello good morning
7 return 0;
(gdb)
as soon as i try to step into the printf function.its exiting and returning to main.
does this mean that the shred library in which the printf function is defined is not provided with the debug symbols?Or am i doing something wrong?
This means there's no available source/debug symbols for printf. You can use stepi to step into printf anyway, you'll only have disassembly available (use the disas command).
That's correct, you likely do not have debugging symbols available. Make sure libc-devel or similar is installed. Also, make sure to compile with -O0 to prevent optimization; optimizations make debugging more difficult to follow.
Also, -g3 is required for maximum symbols. With -g3, even symbolic constants will be available. -ggdb may be helpful too. Jan from GDB tells us there are no mainline GDB extensions, but Apple may have offered some and omitted backstrem patches.

D2 and gdb issue

Short question: Is there any support of D2 in gdb (I have gdb 7.2) ?
Long story: I compiled next little application ...
// file main.d
int glVar = 0xAAAAAAAA;
void main()
{
glVar = 0xBBBBBBBB;
}
... using command "dmd -gc -debug main.d";
then I load it to gdb and trying to debug it:
vnm#vnm:~/proj/d_gdb_test$ gdb main
GNU gdb (GDB) 7.2-ubuntu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
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 "i686-linux-gnu".
For bug reporting instructions, please see:
...
Reading symbols from /home/vnm/proj/d_gbb_test/main...done.
(gdb) b main
Breakpoint 1 at 0x804b667
(gdb) r
Starting program: /home/vnm/proj/d_gbb_test/main
[Thread debugging using libthread_db enabled]
Breakpoint 1, 0x0804b667 in main ()
(gdb) info line
No line number information available.
(gdb) info variables glVar
All variables matching regular expression "glVar":
File main.d:
int _D4main5glVari;
Why gdb can't show line information and why it shows symbols in mangled form ? Is this software issues or I'm doing something wrong ?
gdb has support for D starting with version 7.2. So, you can debug D programs with gdb 7.2.
Now, that doesn't mean that support is perfect - far from it in fact. For instance, I'm not sure that you can get it to print strings properly. And it's not at all surprising if it doesn't demangle D symbols. So, it works, but it's far from perfect.

Debugging MinGW program with gdb on Windows, not terminating at assert failure

How do I set up gdb on window so that it does not allow a program with assertion failure to terminate? I intend to check the stack trace and variables in the program.
For example, running this test.cpp program compiled with MinGW 'g++ -g test.cpp -o test' in gdb:
#include <cassert>
int main(int argc, char ** argv) { assert(1==2); return 0; }
Gives:
$ gdb test.exe
GNU gdb 6.8
Copyright (C) 2008 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 "i686-pc-mingw32"...
(gdb) r
Starting program: f:\code/test.exe
[New thread 4616.0x1200]
Error: dll starting at 0x77030000 not found.
Error: dll starting at 0x75f80000 not found.
Error: dll starting at 0x77030000 not found.
Error: dll starting at 0x76f30000 not found.
Assertion failed: 1==2, file test.cpp, line 2
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
Program exited with code 03.
(gdb)
I would like to be able to stop the program from terminating immediately, like how Visual Studio's debugger and gdb on Linux does it. I have done a search and found some stuff on trapping signals but I can't seem to find a good post on how to set up gdb to do this.
Found out that the breakpoint can be put in the .gdbinit file with the lines:
set breakpoint pending on
b exit
This removes the need to enter yes for windows.
Just set a breakpoint on exit:
(gdb) b exit
Using recent (March 2017) msys2 with gcc 6.3 and gdb 7.12.1 you should use:
break _exit
i.e. use _exit and not exit. I expect this also to work in other cases as I expect that exit will call _exit to actually exit.