Ada GNATStudio gdb Breakpoints are not stopping in the debugger - debugging

I'm new to Ada, and I created a sample program.
with Text_IO; use Text_IO;
procedure Main is
Index : Integer;
begin
Index := 123;
-- Integer'Image means Int to str
Put_Line (Integer'Image (Index));
New_Line;
end Main;
When I put a breakpoint in Main, on the line Put_Line, the program continues on as if I never set it.
Here's what I do to debug it. Please correct me if I'm doing something wrong.
Set breakpoint on line 12.
Debugger Menu Item -> Initialize -> main
Debugger -> Start
Run Arguments: (nothing)
Unchecked "Stop at the beginning of main subprogram"
Unchecked "Use exec dir instead of current dir"
EDIT:
I solved this myself, I had to do a clean and build all, THEN go into Debugger Menu Item -> Initialize -> main
That gives me the little green line to start the debugger!

I solved this myself, I had to do a clean and build all, THEN go into Debugger Menu Item -> Initialize -> main
That gives me the little green line to start the debugger!
Perform a 'Clean All' and make sure '-g' is used in the build path when you perform a 'Build All'.
Debugger Menu Item -> Initialize -> main
Debugger -> Start
Run Arguments: (nothing) Unchecked "Stop at the beginning of main subprogram" Unchecked "Use exec dir instead of current dir"

Related

Debugging with GDB - seeing code around a given breakpoint

I am trying to debug a C++ program using GDB. I have set 15 breakpoints. Most of the breakpoints are in different files. After the first 5 breakpoints, it became difficult to remember what line of code any given breakpoint refers to.
I struggle quite a bit simply trying to recall what a given breakpoint refers to. I find this quite distracting. I was wondering if there is a way to tell gdb to display code around a certain breakpoint.
Something like this - $(gdb) code 3 shows 30 lines of code around breakpoint 3. Is this possible today. Could you please show me how?
I run gdb in tui mode, and I also keep emacs open to edit my source files.
You can use gdb within emacs.
In emacs, type M-x gdb, after entering the name of the executable, type M-x gdb-many-windows. It brings up an IDE-like interface, with access to debugger, locals, source, input/output, stack frame and breakpoints.
You can find a reference and snapshot here.
I don't think you can do it exactly like this in gdb as such, but it can be scripted in gdb python.
This crude script should help:
import gdb
class Listbreak (gdb.Command):
""" listbreak n Lists code around breakpoint """
def __init__ (self):
super(Listbreak, self).__init__ ("listbreak", gdb.COMMAND_DATA)
def invoke (self, arg, from_tty):
printed = 0
for bp in gdb.breakpoints():
if bp.number == int(arg[0]):
printed = 1
print ("Code around breakpoint " + arg[0] + " (" + bp.location + "):")
gdb.execute("list " + bp.location)
if printed == 0:
print ("No such breakpoint")
Listbreak()
Copy this to listbreak.py, source it in gdb (source listbreak.py), then use it like this:
listbreak 2

Set breakpoint on symbol with lldb

I am trying to set a breakpoint on a function but lldb gives me an error "WARNING: Unable to resolve breakpoints to any actual locations.."
Following their example over at http://lldb.llvm.org/lldb-gdb.html , I have to use breakpoint set --method xxxxxxxxx
The function where I try to set a breakpoint is called
pf::WebViewImpl::~WebViewImpl()
__ZN2pf11WebViewImplD1Ev
Which one should I use to be able to set a breakpoint?
You can put a breakpoint on your destructor using the --method option,
(lldb) br s -M ~WebViewImpl
You can use the --name option with just the dtor method name too,
(lldb) br s -n ~WebViewImpl
and lldb should find it. Finally, you can pass the mangled name to breakpoint set and that will work as well,
(lldb) br s -n _ZN2pf11WebViewImplD1Ev
Note that there's only one underscore in the mangled name - nm(1)'s output will list a leading underscore that you need to omit.
If this method is in a shared library or framework and the process hasn't launched yet, then lldb is correct in saying "Unable to resolve breakpoint to any actual locations". Once your process starts running, the framework/solib will be loaded, lldb will evaluate all breakpoints and see that it now has a valid location.

How to set a breakpoint with lldb + mono

I have the following C# program (test.cs) which I want to debug:
using System;
using System.Collections.Generic;
class Program
{
static void Main(string[] args)
{
Console.WriteLine( "Hello, World!" );
List<int> list = new List<int>();
list.Add(123);
list.Add(234);
list.Add(345);
list.Add(456);
int number = 4;
++number;
Console.WriteLine(" number " + number); // <--- L:16 I want to set a breakpoint here :)
Console.WriteLine("Number of elements" + list.Count);
foreach (Object obj in list)
{
Console.WriteLine(" " + obj);
}
Console.WriteLine("Bye");
}
}
And below is the debug session using lldb and mono (I am in OSX). I can start the session and run the program however I am not able to setup any breakpoint. I guess that when using mono as the executable file things are different. How can I achieve this?
$ mcs -debug test.cs
$ lldb
(lldb) target create mono
Current executable set to 'mono' (i386).
(lldb) b test.cs:16
Breakpoint 1: no locations (pending).
WARNING: Unable to resolve breakpoint to any actual locations.
(lldb) run --debug test.exe
Process 15191 launched: '/usr/bin/mono' (i386)
Hello, World!
number 5
Number of elements4
123
234
345
456
Bye
Process 15191 exited with status = 0 (0x00000000)
(lldb)
I've tried with GBD as this old guide suggests but it is worse, apparently there is something broken in mono in OSX that makes it impossible to debug unless the soft debugger is used (which is exactly what I want to avoid. MonoDevelop debugger is really really unstable/unreliable/slow). This is what I have tried with GBD. No luck at all.
And help is appreciated.
Isn't mono the interpreter for your language and test.exe the binary? lldb only knows about mono -- any breakpoints you try to set would be in the mono interpreter. e.g. if you were debugging an issue with mono itself.
This is a unique enough environment that you'll need to do a little analysis to understand what lldb sees. What do you get for
(lldb) image list test.exe
? Of course if you do
(lldb) im li mono
You'll see mono listed -- because that's a binary that lldb knows about. (you can use plain image list aka im li to see all the binaries that lldb knows)
You can ask lldb to list all of the line table entries based on a source filename with a command line
(lldb) target modules dump line-table test.cs
if lldb has any debug information for a test.cs, you'll see a line table. Without a line table, file and line breakpoints (b test.cs:16) won't work.
For what it's worth, I don't think trying to use lldb (or gdb) to debug your C# program will work. You'll probably need to use some facility of the mono runtime itself to set breakpoints and examine program state.

how to debug program with argument vector in Xcode

I'm new in OS X.
I'm writing programs with UNIX system calls in Xcode.
I'd like to debug program with argument vector line by line.
But I don't know how I can put argument value into **argv.
Assume that executable file has the name 'a.out', which I want to debug line by line in Xcode. All I have to do is let the program be initially set argv to the following.
argv[0] = "./a.out"
argv[1] = "ls"
argv[2] = "foo"
argv[3] = "-l"
What Should I do? Thank you in advance.
Do you mean you want to pass in arguments to your program when you debug? If so, click on the name of your target in the drop-down menu next to Run and Stop, go down to "Edit Scheme...", and then click on the arguments tab. You can add arguments to pass in there.

Setting breakpoint in different file has no effect

The ruby debugger does not halt on breakpoints I set in files different from the on the execution starts in. For example, consider these two files, foo.rb:
# foo.rb
class Foo
def bar
puts "baz"
end
end
and main.rb:
# main.rb
require './foo'
Foo.new.bar
I start debugging using ruby -r debug .\main.rb. Now, when I try to set a breakpoint on a specific line in another file using b ./foo.rb:4, I get the message Set breakpoint 1 at foo.rb:4, but when I cont, the program executes to the end, and the debugger never halts. However, if I break on a line in main.rb, e.g. b ./main.rb:3, or a method, e.g. b Foo.bar, the debugger halts as expected.
Why doesn't the debugger halt at breakpoints in files other than the main file?
Update: I have tried this with Ruby 1.9.3 on Windows 7 as well as OS X 10.8; it doesn't work in either environment.
I have also just realized that the debugger quits after the script has run till the end: I start debugging main.rb, use cont, then baz is printed on the console and I'm right back in the shell. Is this the expected behaviour, or might the debugger have crashed?
Wow, that is weird. Not sure if this helps, but maybe you could do this. Step over the require with next so that Foo is loaded then
b Foo:bar
that should at least break on bar

Resources