lldb python basic - print value of a global array while inside a breakpoint in a function
(Some background: I am not experienced with lldb or python and don't work on them frequently, but currently need to make some basic scripts for debugging an iphone program)
I am currently stopped at a breakpoint in side a function, and want to check the value of an array that has been accessed inside this function
This array is declared as
Float32 my_array[128];
and has global scope. I can view the array using print command, but I would like to make a python script so that I have more control over the output formatting and possibly plot the array elements as a graph using matplolib later on.
I am looking at the sample python code given in this question, and using the python given there I have verified that I can view local variables in this function (where currently I am stopped at a break point). For example, if I change 'base' in base=frame.FindVariable('base')
to my local variable 'k' (the local variable is not an array) ,
base=frame.FindVariable('k')
then print base
I can see the value of k. However, if I try this,
base=frame.FindVariable('my_array')
and do print base
it gives me No value
. How can I write a python command to get the values of any kind of variable currently in scope? Preferably it works for normal variables (int, float), arrays, and pointers, but if not, finding values of arrays are more important at the moment.
ios xcode python-2.7 lldb
add a comment |
(Some background: I am not experienced with lldb or python and don't work on them frequently, but currently need to make some basic scripts for debugging an iphone program)
I am currently stopped at a breakpoint in side a function, and want to check the value of an array that has been accessed inside this function
This array is declared as
Float32 my_array[128];
and has global scope. I can view the array using print command, but I would like to make a python script so that I have more control over the output formatting and possibly plot the array elements as a graph using matplolib later on.
I am looking at the sample python code given in this question, and using the python given there I have verified that I can view local variables in this function (where currently I am stopped at a break point). For example, if I change 'base' in base=frame.FindVariable('base')
to my local variable 'k' (the local variable is not an array) ,
base=frame.FindVariable('k')
then print base
I can see the value of k. However, if I try this,
base=frame.FindVariable('my_array')
and do print base
it gives me No value
. How can I write a python command to get the values of any kind of variable currently in scope? Preferably it works for normal variables (int, float), arrays, and pointers, but if not, finding values of arrays are more important at the moment.
ios xcode python-2.7 lldb
add a comment |
(Some background: I am not experienced with lldb or python and don't work on them frequently, but currently need to make some basic scripts for debugging an iphone program)
I am currently stopped at a breakpoint in side a function, and want to check the value of an array that has been accessed inside this function
This array is declared as
Float32 my_array[128];
and has global scope. I can view the array using print command, but I would like to make a python script so that I have more control over the output formatting and possibly plot the array elements as a graph using matplolib later on.
I am looking at the sample python code given in this question, and using the python given there I have verified that I can view local variables in this function (where currently I am stopped at a break point). For example, if I change 'base' in base=frame.FindVariable('base')
to my local variable 'k' (the local variable is not an array) ,
base=frame.FindVariable('k')
then print base
I can see the value of k. However, if I try this,
base=frame.FindVariable('my_array')
and do print base
it gives me No value
. How can I write a python command to get the values of any kind of variable currently in scope? Preferably it works for normal variables (int, float), arrays, and pointers, but if not, finding values of arrays are more important at the moment.
ios xcode python-2.7 lldb
(Some background: I am not experienced with lldb or python and don't work on them frequently, but currently need to make some basic scripts for debugging an iphone program)
I am currently stopped at a breakpoint in side a function, and want to check the value of an array that has been accessed inside this function
This array is declared as
Float32 my_array[128];
and has global scope. I can view the array using print command, but I would like to make a python script so that I have more control over the output formatting and possibly plot the array elements as a graph using matplolib later on.
I am looking at the sample python code given in this question, and using the python given there I have verified that I can view local variables in this function (where currently I am stopped at a break point). For example, if I change 'base' in base=frame.FindVariable('base')
to my local variable 'k' (the local variable is not an array) ,
base=frame.FindVariable('k')
then print base
I can see the value of k. However, if I try this,
base=frame.FindVariable('my_array')
and do print base
it gives me No value
. How can I write a python command to get the values of any kind of variable currently in scope? Preferably it works for normal variables (int, float), arrays, and pointers, but if not, finding values of arrays are more important at the moment.
ios xcode python-2.7 lldb
ios xcode python-2.7 lldb
edited Nov 16 at 5:19
asked Nov 16 at 4:49
user13267
2,682175591
2,682175591
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
SBFrame.FindVariable
searches among the variables local to that frame. It doesn't search among the global variables.
For that you need to use a search with a wider scope. If you know that the global variable is in the binary image containing the your frame's code - lldb calls that binary image a Module
- then you can find the module containing that frame and use SBModule.FindGlobalVariables
. If that's not true, you can search the whole target using SBTarget.FindGlobalVariables
. If you know that only one global variable of that name exists, you can use FindFirstGlobalVariable
variant.
All these commands will find variables of any type, and they all consistently return SBValue
s so you can format them in a consistent manner regardless of how you find them. For statically allocated arrays, the array elements are its children, so you can fetch individual elements with SBValue.GetChildAtIndex.
You can get to a SBFrame
's module like:
module = frame.module
and its target:
target = frame.thread.process.target
lldb separates the contexts in which to search for variables primarily for efficiency. If SBFrame.FindVariable
searched for globals as well as locals, a mistyped variable name would be a much more expensive mistake. But it also makes the call more predictable since you will never get some random global from some shared library that the system loaded on your behalf.
hi I managed to read values of the individual elements of the array in lldb python thanks to your help, but the main thing I wanted to do, display the array values in a graph using matplotlib, is not working. Would you mind having a look at my other question please? stackoverflow.com/questions/53367537/…
– user13267
Nov 19 at 2:40
I recently found your answer here: stackoverflow.com/a/36706767/1693203 Does this mean generating maltplotlib from Xcode lldb terminal is impossible?
– user13267
Nov 19 at 6:44
I think it's better to give up on matplotlib from within Xcode lldb console. Would you mind having a look at my other question please? stackoverflow.com/questions/53373971/…
– user13267
Nov 19 at 11:47
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53331618%2flldb-python-basic-print-value-of-a-global-array-while-inside-a-breakpoint-in-a%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
SBFrame.FindVariable
searches among the variables local to that frame. It doesn't search among the global variables.
For that you need to use a search with a wider scope. If you know that the global variable is in the binary image containing the your frame's code - lldb calls that binary image a Module
- then you can find the module containing that frame and use SBModule.FindGlobalVariables
. If that's not true, you can search the whole target using SBTarget.FindGlobalVariables
. If you know that only one global variable of that name exists, you can use FindFirstGlobalVariable
variant.
All these commands will find variables of any type, and they all consistently return SBValue
s so you can format them in a consistent manner regardless of how you find them. For statically allocated arrays, the array elements are its children, so you can fetch individual elements with SBValue.GetChildAtIndex.
You can get to a SBFrame
's module like:
module = frame.module
and its target:
target = frame.thread.process.target
lldb separates the contexts in which to search for variables primarily for efficiency. If SBFrame.FindVariable
searched for globals as well as locals, a mistyped variable name would be a much more expensive mistake. But it also makes the call more predictable since you will never get some random global from some shared library that the system loaded on your behalf.
hi I managed to read values of the individual elements of the array in lldb python thanks to your help, but the main thing I wanted to do, display the array values in a graph using matplotlib, is not working. Would you mind having a look at my other question please? stackoverflow.com/questions/53367537/…
– user13267
Nov 19 at 2:40
I recently found your answer here: stackoverflow.com/a/36706767/1693203 Does this mean generating maltplotlib from Xcode lldb terminal is impossible?
– user13267
Nov 19 at 6:44
I think it's better to give up on matplotlib from within Xcode lldb console. Would you mind having a look at my other question please? stackoverflow.com/questions/53373971/…
– user13267
Nov 19 at 11:47
add a comment |
SBFrame.FindVariable
searches among the variables local to that frame. It doesn't search among the global variables.
For that you need to use a search with a wider scope. If you know that the global variable is in the binary image containing the your frame's code - lldb calls that binary image a Module
- then you can find the module containing that frame and use SBModule.FindGlobalVariables
. If that's not true, you can search the whole target using SBTarget.FindGlobalVariables
. If you know that only one global variable of that name exists, you can use FindFirstGlobalVariable
variant.
All these commands will find variables of any type, and they all consistently return SBValue
s so you can format them in a consistent manner regardless of how you find them. For statically allocated arrays, the array elements are its children, so you can fetch individual elements with SBValue.GetChildAtIndex.
You can get to a SBFrame
's module like:
module = frame.module
and its target:
target = frame.thread.process.target
lldb separates the contexts in which to search for variables primarily for efficiency. If SBFrame.FindVariable
searched for globals as well as locals, a mistyped variable name would be a much more expensive mistake. But it also makes the call more predictable since you will never get some random global from some shared library that the system loaded on your behalf.
hi I managed to read values of the individual elements of the array in lldb python thanks to your help, but the main thing I wanted to do, display the array values in a graph using matplotlib, is not working. Would you mind having a look at my other question please? stackoverflow.com/questions/53367537/…
– user13267
Nov 19 at 2:40
I recently found your answer here: stackoverflow.com/a/36706767/1693203 Does this mean generating maltplotlib from Xcode lldb terminal is impossible?
– user13267
Nov 19 at 6:44
I think it's better to give up on matplotlib from within Xcode lldb console. Would you mind having a look at my other question please? stackoverflow.com/questions/53373971/…
– user13267
Nov 19 at 11:47
add a comment |
SBFrame.FindVariable
searches among the variables local to that frame. It doesn't search among the global variables.
For that you need to use a search with a wider scope. If you know that the global variable is in the binary image containing the your frame's code - lldb calls that binary image a Module
- then you can find the module containing that frame and use SBModule.FindGlobalVariables
. If that's not true, you can search the whole target using SBTarget.FindGlobalVariables
. If you know that only one global variable of that name exists, you can use FindFirstGlobalVariable
variant.
All these commands will find variables of any type, and they all consistently return SBValue
s so you can format them in a consistent manner regardless of how you find them. For statically allocated arrays, the array elements are its children, so you can fetch individual elements with SBValue.GetChildAtIndex.
You can get to a SBFrame
's module like:
module = frame.module
and its target:
target = frame.thread.process.target
lldb separates the contexts in which to search for variables primarily for efficiency. If SBFrame.FindVariable
searched for globals as well as locals, a mistyped variable name would be a much more expensive mistake. But it also makes the call more predictable since you will never get some random global from some shared library that the system loaded on your behalf.
SBFrame.FindVariable
searches among the variables local to that frame. It doesn't search among the global variables.
For that you need to use a search with a wider scope. If you know that the global variable is in the binary image containing the your frame's code - lldb calls that binary image a Module
- then you can find the module containing that frame and use SBModule.FindGlobalVariables
. If that's not true, you can search the whole target using SBTarget.FindGlobalVariables
. If you know that only one global variable of that name exists, you can use FindFirstGlobalVariable
variant.
All these commands will find variables of any type, and they all consistently return SBValue
s so you can format them in a consistent manner regardless of how you find them. For statically allocated arrays, the array elements are its children, so you can fetch individual elements with SBValue.GetChildAtIndex.
You can get to a SBFrame
's module like:
module = frame.module
and its target:
target = frame.thread.process.target
lldb separates the contexts in which to search for variables primarily for efficiency. If SBFrame.FindVariable
searched for globals as well as locals, a mistyped variable name would be a much more expensive mistake. But it also makes the call more predictable since you will never get some random global from some shared library that the system loaded on your behalf.
answered Nov 16 at 18:56
Jim Ingham
13.6k12933
13.6k12933
hi I managed to read values of the individual elements of the array in lldb python thanks to your help, but the main thing I wanted to do, display the array values in a graph using matplotlib, is not working. Would you mind having a look at my other question please? stackoverflow.com/questions/53367537/…
– user13267
Nov 19 at 2:40
I recently found your answer here: stackoverflow.com/a/36706767/1693203 Does this mean generating maltplotlib from Xcode lldb terminal is impossible?
– user13267
Nov 19 at 6:44
I think it's better to give up on matplotlib from within Xcode lldb console. Would you mind having a look at my other question please? stackoverflow.com/questions/53373971/…
– user13267
Nov 19 at 11:47
add a comment |
hi I managed to read values of the individual elements of the array in lldb python thanks to your help, but the main thing I wanted to do, display the array values in a graph using matplotlib, is not working. Would you mind having a look at my other question please? stackoverflow.com/questions/53367537/…
– user13267
Nov 19 at 2:40
I recently found your answer here: stackoverflow.com/a/36706767/1693203 Does this mean generating maltplotlib from Xcode lldb terminal is impossible?
– user13267
Nov 19 at 6:44
I think it's better to give up on matplotlib from within Xcode lldb console. Would you mind having a look at my other question please? stackoverflow.com/questions/53373971/…
– user13267
Nov 19 at 11:47
hi I managed to read values of the individual elements of the array in lldb python thanks to your help, but the main thing I wanted to do, display the array values in a graph using matplotlib, is not working. Would you mind having a look at my other question please? stackoverflow.com/questions/53367537/…
– user13267
Nov 19 at 2:40
hi I managed to read values of the individual elements of the array in lldb python thanks to your help, but the main thing I wanted to do, display the array values in a graph using matplotlib, is not working. Would you mind having a look at my other question please? stackoverflow.com/questions/53367537/…
– user13267
Nov 19 at 2:40
I recently found your answer here: stackoverflow.com/a/36706767/1693203 Does this mean generating maltplotlib from Xcode lldb terminal is impossible?
– user13267
Nov 19 at 6:44
I recently found your answer here: stackoverflow.com/a/36706767/1693203 Does this mean generating maltplotlib from Xcode lldb terminal is impossible?
– user13267
Nov 19 at 6:44
I think it's better to give up on matplotlib from within Xcode lldb console. Would you mind having a look at my other question please? stackoverflow.com/questions/53373971/…
– user13267
Nov 19 at 11:47
I think it's better to give up on matplotlib from within Xcode lldb console. Would you mind having a look at my other question please? stackoverflow.com/questions/53373971/…
– user13267
Nov 19 at 11:47
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53331618%2flldb-python-basic-print-value-of-a-global-array-while-inside-a-breakpoint-in-a%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown