Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing all global variables/local variables?

How can I print all global variables/local variables? Is that possible in gdb?

like image 298
cpuer Avatar asked Jun 07 '11 06:06

cpuer


People also ask

How do you print all variables in Python?

To easily display single and multiple variables in Python, use the print() statement. For multiple variables, use the comma operators.

How do I see all defined variables in Python?

Locals() is a built-in function that returns a list of all local variables in that particular scope. And globals() does the same with the global variables. Create a list of all global variables using globals( ) function, to store the built-in global variables.

How do you find global and local variables?

The main difference between Global and local variables is that global variables can be accessed globally in the entire program, whereas local variables can be accessed only within the function or block in which they are defined.

Can a variable be both local and global?

Within a function, each variable is either local or global When you have two variables of the same name, a global variable, and a local variable, inside your function, that variable name will always be either global or local. One variable cannot be both global and local inside the same function.


1 Answers

Type info variables to list "All global and static variable names" (huge list.

Type info locals to list "Local variables of current stack frame" (names and values), including static variables in that function.

Type info args to list "Arguments of the current stack frame" (names and values).

like image 137
kennytm Avatar answered Oct 01 '22 14:10

kennytm