Value from Variable View on Pydev is not complete - pydev

I tried to debug a python module, I saw in the Variables view that the value of a variable is not complete.
This ends with "...". I think this means that the string was truncated.
In the Details pane from Variable view I set to display the Max Length of the variable (0=unlimited) but also in the Details pane the variable ends with "...".
Why the variable don't have the full value?

Yes, this means that the string was truncated.
That value is hardcoded in pydevd -- it can be changed manually be editing eclipse/plugins/org.python.pydev.core/pysrc/_pydevd_bundle/pydevd_comm.py -- MAX_IO_MSG_SIZE in your install.
Now, usually this isn't a real problem because it's possible to just use the console during the debug session and print the variable in the console to view its full values (see: http://www.pydev.org/manual_adv_debugger.html -- search for console evaluation there).

Related

Not supporting hover variable with hyphen in vscode extension

For debugging Cobol program using vscode extension I have extended debug extension protocol. I have variables with hyphen in my cobol program e.g: emp-salary.
I have set the flag supportsEvaluateForHovers to true.
While debugging I am trying to hover this kind of variable but, value I am getting inside evaluateRequest method is NOT considering this as complete one variable name and just returning hyphen separated part of variable. For example out of emp-salary I do mouse hover over emp it is returning emp only.
My expectation is it shall return emp-salary as it is single variable name.
What exact changes I will need to implement in my code so it will consider hyphen separated variable as one variable?
Try enabling the "Use Managed Compatibility Mode" flag under Debugging. This worked for me today using VS 2019.

Copying variable contents to clipboard while debugging in Visual Studio Code

I'm debugging in Visual Studio Code and I have a JSON object that I would like to copy as text to the clipboard.
Is this possible inside of Visual Studio Code?
I found two ways to do that, both of which are a bit hacky (in my eyes).
Use console.log
I think there will be a limit to the size of the string that this can output, but it was satisfactory for my requirements.
In the debug console, write console.log(JSON.stringify(yourJsonObject))
Copy the resulting output from the debug console. That can be a bit tedious for long strings, but a combination of mouse and keyboard (ctrl-shift-end) worked ok for me.
Use a watch (limited to 10'000 characters)
This method only works up to a limited size of the resulting json string (it looks like 10'000 characters).
Set a breakpoint in a reasonable location where your variable is in scope and start your app.
Go to the debug view, add a watch for a temporary variable, e.g. tmpJson
Get your breakpoint to hit.
In the debug console, write var tmpJson = JSON.stringify(yourJsonObject)
This will now have populated the watched variable tmpJson with the string representation of your json object
In the debug view, right click on the watched variable, click copy.
If the string is too long, it cuts it off with a message like the following:
...,"typeName":"rouParallel","toolAssembly":{"id":"ASKA800201","description":"CeonoglodaloD50R6z5","c... (length: 80365)"
But it would work for smaller objects. Maybe this helps some people.
It would be great to have this properly built-in with vscode.
There is an open issue regarding this: https://github.com/microsoft/vscode-java-debug/issues/624
Workaround :
Go to the VARIABLES panel and right click to show contextual menu on a variable
select Set Value
Ctrl+C
(tested on Java, not JavaScript)
I have an easy workaround to copy anything you want:
In the debug console, write JSON.stringify(yourJsonObject)
Copy the string without the double quotes " around the string
Open a browser, such as Chrome, open the inspecting tool, go on the console and write:
copy(JSON.parse("PASTE_THE_STRING_HERE"));
The object is now copy on your keyboard !
If you are debugging Python:
In the DEBUG CONSOLE type, for example:
import json
from pprint import pprint as pp
pp(json.dumps(outDetailsDict))
OUTPUT IS LIKE
{"": {"stn_ix": 43, "stn_name": "Historic Folsom Station (WB)", "name": "", },
...
The fastest way I found to do that on Visual Studio Code was
Adding a breakpoint where is located the object to copy
Right click on object and choose "Add to Watch"
From Watch sidebar, choose option "Copy Value" and it's all! 🎉
Note: this solution seems to work for longer values but not very long values. This answer suggests a 10,000 char limit and uses JSON.stringify(myvar) instead of just str(). On char limit, see also this comment below.
Tested in python debugger
Add the variable to Watch, but converted to string
str(myvar)
Right-click on the value of the watch, and select Copy Value
Now you should get the full value (but not for very long values. See note above).
(var name blurred out):
If you're in debug mode, you can copy any variable by writing copy() in the debug terminal.
This works with nested objects and also removes truncation and copies the complete value.
Tip: you can right click a variable, and click Copy as Expression and then paste that in the copy-function.
While the question presumably deals with JavaScript (JSON) based technologies, many people have posted Python-related posts in this thread. So I'll post a more specific answer for Python, although the reasoning can be extended with some tweaks to JavaScript-based technologies. 😊
Helper strategies for debugging with VSCode
Copying variable FULL VALUE (not truncated) to clipboard while debugging even for very long values and other additional strategies.
1 APPROACH: Access the "Run and Debug" screen and look for the "WATCH" area and double click inside it. Add something like str(<MY_VAR>) which should be the variable you want to find the value of during the debug process;
2 APPROACH: Access the "DEBUG CONSOLE" tab and in the footer (symbol ">") copy and paste the code below or another one of your choice...
def print_py_obj(py_obj, print_id="print_py_obj"):
"""Prints a Python object with its string, type, dir, dict, etc...
Args:
py_obj (Any): Any Python object;
print_id (Optional[str]): Some identifier.
"""
print(" " + str(print_id) + \
" DEBUG >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
print(" 0 STR >>>>>>>>>>>>>>>>>>>>>>>>")
print(str(py_obj))
print(" 0 <<<<<<<<<<<<<<<<<<<<<<<<")
print(" 1 TYPE >>>>>>>>>>>>>>>>>>>>>>>>")
print(type(py_obj))
print(" 1 <<<<<<<<<<<<<<<<<<<<<<<<")
print(" 2 DIR >>>>>>>>>>>>>>>>>>>>>>>>")
print(str(dir(py_obj)))
print(" 2 <<<<<<<<<<<<<<<<<<<<<<<<")
print(" 3 DICT >>>>>>>>>>>>>>>>>>>>>>>>")
try:
print(vars(py_obj))
except Exception:
pass
print(" 3 <<<<<<<<<<<<<<<<<<<<<<<<")
print(" " + str(print_id) + \
" DEBUG <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
print_py_obj(profit, "<MY_VAR_OPTIONAL_IDENTIFIER>")
NOTE: We may have a 10,000 character limitation for both approaches.
Thanks! 🤗🐧🐍
Yup ! That's very much possible
Select breakpoint near your json variable.Debug.
screnshot . Right click on json body and copy value.That's it.
On the selected breakpoint, go to the Debug Console and print(variable)

Print query results when using format=alinged, instead of open them in EDITOR

If a do a select and only retrieve a few columns, the results are printed to the terminal, if I have more columns, and they do not fit in the terminal width, the query results are opened in the default editor (vim), but when I exit the editor the results are no longer visible.
I know I can user \x (but I have many rows, and for my it's seems worst ).
If I change the format to unaligned, html, latex or troff-ms even if the results are wider then the terminal width they are still printed.
When the resulted rows do not fit in the terminal height they are always opened in the default EDITOR, no mater what format I am using.
Q:
There is any posibility to use format=aligned and allways print the results instead of opening them in the default EDITOR, so I will not loose their visibility (something similar to what mysql-client does) ?
Thank you.
The query results are passed to the PAGER program when they don't fit in the screen, unless it's disabled with \pset pager off. EDITOR is used for input.
Some pagers restore the previous display when they quit, and it can be quite irritating when you need to use previous results in further queries.
I've found PAGER="less -FX" to be a good fit with psql since it allows scrolling in both directions and keeps the display intact when it quits.

Setting Memory Breakpoints in Eclipse

How do you set memory breakpoints in Eclipse? That is, I would like to set a conditional breakpoint that triggers when the data at a given memory location changes.
This question has been asked before, but the only provided answer doesn't address the question and is essentially the same information that can be found in the Eclipse Online help.
What I am looking for is more detailed information (or an example would be good) for setting a conditional breakpoint in Eclipse that will trigger when the data at a specific memory address changes.
You need to use a watchpoint. From the page:
Highlight the variable in the editor, or select it in the Outline
view.
Click Run > Toggle Watchpoint.
Do any of the following:
To stop execution when the watch expression is read, select the Read check box.
To stop execution when the watch expression is written to, select the Write check box.
The watchpoint appears in the Breakpoints view list.
Solution that works:
1/ Select the variable representing the pointer you want to break on in a given context in the "Variables" tab
2/ Right click, then select "Add Watchpoint (C/C++)
3/ In the field "Expression to watch", just replace the name of the variable by the memory address to break on.
Using a Watchpoint in Eclipse Oxygen:
In the Expressions view (Window > Show View > Expressions), add an Expression such as: *(uint8_t*)0x231cc528. The cast tells Eclipse the memory location size.
Right-click the added expression and select "Add Watchpoint".
The resulting Watchpoint may be edited and controlled in the "Breakpoints" view.
It may be important to edit the Watchpoint. If you want to e.g. detect changes done by other threads: right-click the Watchpoint in the "Breakpoints" view, select Breakpoint Properties... > Filter, UN-check "Restrict to Selected Processes and Threads"

How to Handle Tcl Treeview Selections

I am using the following procedure to delete a record within a database that is displayed within a treeview widget (z1):
set z1 [ttk::treeview .c1.t1 -columns {first last} -show headings]
proc Dlt {} {
global z1 z11
sqlite3 db test.db
db eval {
DELETE From t1 Where First_Name = $z11 and Last_Name = $z11
}
db close
}
$z11 in the sql statement should be the treeview selection. Unfortunately, I cannot figure out how to set a variable to equal the treeview selection. I can set a variable to equal the index, which is: set z11 [$z1 index [$z1 selection]]. This will give me the index of the treeview selection; however, I am trying to get the string value of the treeview selection.
Does anyone know what the correct syntax is to set a variable to equal a treeview selection?
Thank you,
To get the values for an item in the tree you would use the item subcommand of the tree. For example:
set selection [.tree selection]
set text [.tree item $selection -text]
This is all documented on the man page for the treeview widget.
As an aside, what platform are you working with? If Windows, for debugging purposes, you can add a "console show" command to your code to display an interactive console window. With that open, you can just use [puts] to display variable values. So, you could just use "puts $text" (from within your code) to see the value of your text variable.
Also, you can just type commands directly into the console for immediate evaluation. In many situations, spending a few minutes in the console can be very enlightening.
If you're not running under Windows, you don't even need the "console show" command, as anything written to stdout should appear in the original shell window.