I've only recently began using the debugger extensively, so I'm not sure if this is a limitation.
When I debug on the iPhone, the variables aren't up to date unless I explicitly view it (ctrl+click -> view variable as expression). Is there a way to view actual variables without viewing explicitly?
Can you clarify your question? You should only be viewing data while the program is stopped -- examining data while it's running, if it works at all, is much less useful. Make sure to set a breakpoint, and then examine data once you've hit the breakpoint.
An alternative to using Xcode's built-in debugging features is to use the gdb console. Type ⌘-Shift-R, or select "Debugging Console" from the menu to open the console. Then, you can type commands like:
# View a variable
print var
# View this object's member variable
print self->memberVar
# Ask an Objective-C object to print itself:
print-object self
You should use print with primitive types (int, char*, etc.) and POD types (structs); you should use print-object with Objective-C objects (NSString, etc.). For more information about print and print-object, type
help print
help print-object
You can also use the abbreviations p and po for print and print-object respectively.
Related
How does one set a symbolic breakpoint in lldb when using Swift? For example, sometimes I use:
(lldb) b set -F '-[UIView(AdditionalLayoutSupport) updateConstraintsIfNeeded]'
But this no longer works:
Breakpoint 2: no locations (pending). WARNING: Unable to resolve
breakpoint to any actual locations.
I've also tried
(lldb) b set -F 'UIView.updateConstraintsIfNeeded()'
(lldb) b set -F 'UIView.updateConstraintsIfNeeded'
But no love. I guess the question comes down to what lldb considers a "fully qualified function name" when using Swift. The docs say:
-F ( --fullname )
Set the breakpoint by fully qualified function names. For C++ this
means namespaces and all arguments, and for Objective C this means
a full function prototype with class and selector. Can be repeated
multiple times to make one breakpoint for multiple names.
What about Swift?
When lldb is setting breakpoints any of the fancier matching breakpoints (including -F), it needs to know the target language since the kinds of matching it does depends on that. By default, lldb chooses the language of the current frame, but you can override that. So for instance to break on an ObjC symbol when you are stopped in a Swift frame, do:
(lldb) break set -F '-[UIView(AdditionalLayoutSupport) updateConstraintsIfNeeded]' -L objc
Breakpoint 3: where = UIKit`-[UIView(AdditionalLayoutSupport) updateConstraintsIfNeeded], address = 0x0000000100963acc
Or you can use the -n break option, which doesn't try to understand the symbols it matches, but just does a wide search for that string in the symbol names.
Note, in this case you need to break on the ObjC symbol not the way it appears in Swift, because the swift side is really just a shim into objc, and there isn't really a swift side symbol to hook onto.
In the lldb console, you can give a partial name and get automatic lookup using regex:
br set -r updateConstraintsIfNeeded\]
The result is:
Breakpoint 4: where = UIKit`-[UIView(AdditionalLayoutSupport) updateConstraintsIfNeeded]
In current versions of Xcode, you can also use a partial name in the "add a symbolic breakpoint" UI, because there is now code completion to assist you.
Having some problems with Perl debugger in Eclipse and PadWalker. Only used it for simple one-file scripts before. Variables declared using "my". They appear fine in the debugger "variables" window.
Now I am using someone else's more complicated script and I don't see the variables declared using "our". To investigate, I boiled it down to one very simple example
junk.pl:
use strict;
use warnings;
require 'junk2.pl';
package Junk;
my $simon = "SOMETHING";
print "JUNK " . $Junk2::james . "\n";
print "JUNK " . $simon . "\n";
junk2.pl:
package Junk2;
our $james;
$james = "FOO";
1;
Stepping through the code, the vairable my $simon displays in the debugger window fine but variable our $james does not. The debugger is working OK: the program runs and the output window shows the correct output... it's just the variables window that fails to show $james.
The screen shot below demonstrates the problem. As you can see the variable $james from the Junk2 package prints ok, but does not appear in the variables display.
Been searching a while for a solution but can't find anything that matches well... any ideas?
EDIT: Have found out that I can "see" the package variables if I use the Perl debugger:
.
Is there a way to have the same output in a friendly manner in the IDE like padwalker shows?
Thank you to guys who have answered so far :)
You can toggle viewing local and global variables under the variables view menu. Variables declared with our are outside of the local scope, and are therefore visible when the global variables option is selected. (I am running eclipse 4.2.1)
To access the variables view menu click the small down arrow on the top right of the variables pane.
Variables declared with our are lexical variables, aliased to package variables (thank you #ikegami for the correction):
our makes a lexical alias to a package variable of the same name in the current package for use within the current lexical scope.
brian d foy has a recent post discussing symbol tables.
The short answer is, you access package variables by looking at the package's symbol table.
In addition, PadWalker has a peek_our method. Package::Stash provides other useful helpers.
In the Eclipse Debug Configuration at -X to the Perl command line to show current package variables.
Edit:
In this case you might need to use the -V command instead.
See http://perldoc.perl.org/perldebug.html
Edit:
It would probably be easier to just assign the Junk2::James variable to local variable.
my $james = $Junk2::james;
While debugging an iOS application, I know how to print values of objects using :
print "variable name"
po "variable name"
p "integer Variables"
I wanted to know how to print value of a constant while debugging in Xcode?
Is there any command that prints value of a constant? Because, if I use the above commands, the Xcode returns an error saying
error: use of undeclared identifier
Thanks.
Macros (what you get when you #define something) are the domain of the language preprocessor. They are expanded and the expanded value is used when compiling your code.
The debugger doesn't parse your source file, it works off of what's in the binary. So no, you won't be able to view the value of #define macros in the debugger.
Old question, but nowadays compiling with -g3 (GCC) or -fdebug-macro (Clang) will generate debug information for such preprocessor macros.
Have a look here
Can Perl method calls be intercepted?
It shows how to rewrite the symbol table for a simple sub. The print command can take a list I believe, so what is the right way to intercept/rewrite it? I wish to get a program to delay printing while maintaining the same signature, and instead push the output into an array, pre-sort it, then regurgitate all the output at the very end.
Intercepting print itself isn't the way to go -- it has a number of operating modes, including writing to a file or socket. Instead, take a look at the select function, which can be used to change the default filehandle which print will write to.
Also, look at the concept of a "tied" IO handle, as used by IO::Capture.
After swaping compiler to LLVM 3.0 and libc++ to have C++11 suport (unique_ptr is a little jewel :)) I have noticed gdb is not working properly when I try to print an object information. What I have tested is the following:
1) I have a std::vector < std::unique_ptr > member variable. If I set a breakpoint inside the class containing this member var and do a "print _reusableEntities.size()" I get this:
Breakpoint 2, GameObjectMgr::createGameObject (this=0x0) at /Users/hexdump/Dropbox/Games prototypes/Re-World/src/ReWorld/Engine/EntityManagement/GameObjectMgr.mm:92
92 go=std::move(_reusableEntities.back());
The program being debugged stopped while in a function called from GDB.
When the function (GameObjectMgr::createGameObject()) is done executing, GDB will silently
stop (instead of continuing to evaluate the expression containing
the function call).
But if I have a line of code like:
int size=_reusableEntities.size()
it reads the size ok. It really seems a gdb problem when inspecting the vector size. In the other hand I can see how the vector contains correct values in the Local vars windows.
Another thing that is really weird is why the error shows information related to createGameObject function because It has nothing to do with the gdb command call and I wasn't inside it when trying to print the values.
It is really weird and a pain in the ass when debugging.
2) I have F7 configured to step over functions. This worked until I made this changes, now, it doesn't matter if I push F6 (step into) or F7 (step over) I'm always getting inside unique_ptr code when copying, or getting raw pointer from it :/.
If anyone could guess what is happening I would be really grateful, anyway, I know it is really difficult to guess from just my explanation. If anyone needs more info, please, ask for it.