I have a breakpoint action and am using the Log option from the drop down. I'd like to print out the string (summary) value. I'm doing this:
the person name is: #p.name#
but that prints the memory address. I can switch to the Debugger Command option and do
po f.name
but then I lose my description, as used in the first option. Using the Log option, is there a way to print the string value and not the memory address?
You can use NSLog statements with breakpoints using "Debugger Command", but you need to add "expr"
expr (void)NSLog(#"The Person Name is %#", p.name)
-
There are a couple of things you can do. Add a Log function from the drop-down, then add another box and select Debugger Command and enter po f.name.
If you want your log to be more complicated, you could do something more like this:
the person name is: #(const char *)[(NSString*)[p.name description] UTF8String]#
You best bet is probably to just use the debugger's graphical interface to watch variables. If you want to log messages, use NSLog.
Here is a solution using only one action, and using fewer characters than the expr solution.
However, unless you add the void like this:
po (void)NSLog(#"the person name is: %#", p.name)
you will get an annoying "nil" printed out with your log. for example:
(lldb) po NSLog(#"foo")
nil
2013-06-19 14:42:59.025 TheMove[95864:c07] foo
(lldb) po (void)NSLog(#"foo")
2013-06-19 14:43:10.758 TheMove[95864:c07] foo
If you can live with the nil (I can) it's faster to type and easier to remember just the po
I ended up using 2 different actions for the same breakpoint. First a Log and then a debugger command with po varName. Only downside it will print in 2 different rows.
For Swift and Xcode 12.2 you can double click on the breakpoint and use Debugger Command as an action and as a command whatever you usually time on the debugger.
In the example I use po with a string as param (to avoid printing the memory address) which contains the values I am debugging. I also enable Automatically continue... to avoid stopping the execution.
You can also add other text or other variables.
A thing to keep in mind though, running these takes some time, so for operations where timing is important, these are not good.
You don't need TWO actions in the breakpoint, you can just have ONE command (log message), where you put the message including the content of variables (see image). By clicking "automatically continues" it is just acting like having a print-command in code, but the good thing is, then you dont have print statements in your code.
Related
I am very new to Selenium and Eclipse.
I have a question (actually 2 questions) about debugging.
When I am debugging in Eclipse (Version: 2021-06 (4.20.0)), so I do not get visibility of all variables I have defined in the method.
For example, (see the screen shot attached) I have added string variable testSigned and assigned a value to it. Actually the purpose is to verify the text value contained in web element table_AdditionalDocumentation.
I defined Toggle Line breakpoint at line 395.
I started to execute in debug mode, got to the line 395.
However, I do not see the value of testSigned in Variables tab.
I noticed it does show values only of the variable which would be returned by the method, correct me if I am wrong.
Please, tell me how to get those values I have defined visible.
2.Additionally, please, let me know which button to press if for example after line 395 I want not to go line by line (F6), but just to run the code to the end.
For the first question, I'm not certain, but it might be because you haven't initialized that variable with a value. Try setting it to an empty string on the declaration line.
For the second question, if you set a breakpoint on the line you want to get to, just Resume (F8), and it will stop at the next breakpoint it hits, hopefully the one at the end of your method. Alternatively, if you just want to stop at the line right after the method returns (which will show the return value), you can click "Step Out" (F7) for that.
I am using emacs for programming, and recently also gdb.
The "locals" window does show local variables but not arguments to a function, which in a way also could be considered local variables. For example, if I have
void foo(char *bar)
{
int n;
....
}
then n is shown in the "locals" but not bar. Of course, I can print bar but it is not automatically updated while I step through the code and I have to print all the time.
Is there a way to add expressions that are shown in a window and constantly updated as I execute the code?
The display command will certainly fulfill your needs:
If you find that you want to print the value of an expression frequently (to see how it changes), you might want to add it to the
automatic display list so that GDB prints its value each time your
program stops.
By example, once that your are in foo body (under gdb), type:
display bar
The interactive command gud-watch will watch the expression at point and display its value in the speedbar. Prefix it with C-u to be able to enter an expression.
See the manual page Watch Expressions for more details.
At the moment there doesn't seem to be a way to display watched expressions in the locals window.
I have used Eclipse and VS. When I insert a breakpoint and debug the program, it will stop before the breakpoint.
But what if I want to debug the effect of the last sentence of the program? Inserting a meaningless sentence(say print 'pause' in Python) is OK but seems awkward. Is there any alternatives?
In Visual Studio you can put break point on closing bracket in main (or any) method of Program (or any) class (default naming, may vary), then debugger stops just before closing application.
Is there any reason not to use a breakpoint on the last statement, like you said, then manually proceed one step? Depending on the debugger, this can also be automated. In GDB, one can use commands N, where N is the breakpoint number, to set a list of (debugger) commands to be executed immediately after a breakpoint is hit.
Is there any command using which we can inspect a object in command line while app is running in DEBUG mode. I do not want to put description message in the code.
Try these resources. one two
(gdb) p varName
Yes sure. If you are debuging, breakpoints are automatically set to on. Just set a breakpoint to the line in which the variable is. The program stops as soon it reaches the line with the breakpoint. Just hold the cursor over the variable and all important data is displayed. I do it also that way all the time. ;-)
I recently discovered that you can set breakpoints in Xcode that will print to the console and auto-continue -- meaning you can insert log statements without having to write NSLog() calls and recompile (on-the-fly logging, woot).
Only problem is that it seems to be a little limited in what you can display when doing a log.
It shows some tokens you can insert, like %B to print out some info about the current breakpoint or %H for the hit count.
I'd like to know if there's any way I can insert a time stamp in a particular format into the log line?
I tried playing with the "shell script" breakpoint action, but it told me that the date command didn't exist.... strange...
Any help would be awesome,
Thanks guys!
Read the GDB manual about Breakpoint Command Lists
You can give any breakpoint (or watchpoint or catchpoint) a series of commands to execute when your program stops due to that breakpoint. For example, you might want to print the values of certain expressions, or enable other breakpoints.
And in particular:
for example, here is how you could use breakpoint commands to print the value of x at entry to foo whenever x is positive.
break foo if x>0
commands
silent
printf "x is %d\n",x
cont
end
Does this answer your question?