How to set a breakpoint that only triggers when within a specific parent function?
I would like to add a breakpoint to a method rb_vm_check_ints
but only when it's called from within rb_ary_collect_bang
. There are several threads executing.
lldb
add a comment |
I would like to add a breakpoint to a method rb_vm_check_ints
but only when it's called from within rb_ary_collect_bang
. There are several threads executing.
lldb
add a comment |
I would like to add a breakpoint to a method rb_vm_check_ints
but only when it's called from within rb_ary_collect_bang
. There are several threads executing.
lldb
I would like to add a breakpoint to a method rb_vm_check_ints
but only when it's called from within rb_ary_collect_bang
. There are several threads executing.
lldb
lldb
asked Nov 13 '18 at 1:50
ioquatixioquatix
882922
882922
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
As a follow up to Jim's answer, this can also be done as a one liner, without creating a named function:
breakpoint command add -s python -o 'return frame.parent.name == "rb_ary_collect_bang"'
lldb creates a wrapper function for you (which has a frame
parameter), and the key is to return
the result of the comparison, because as Jim said, lldb will stop if the result is true, and keep going if the result is false.
This can be extended to looking at any calling function in the stack:
br c add -s python -o 'return any(f.name == "rb_ary_collect_bang" for f in frame.thread)'
This one is a bit more opaque. The expression frame.thread
is an iterator of all frames on the current thread's stack. The expression [f.name for f in frame.thread]
would give you a list of all function names on the stack. The expression any(f.name == "abc" for f in frame.thread)
returns true if the function "abc" is anywhere in the stack.
GDB has some helper functions for these cases, and I wrote a similar set functions for lldb. https://github.com/kastiglione/lldb-helpers. Using these functions you could write:
break com add -F 'caller_is("rb_ary_collect_bang")'
add a comment |
You need to write a Python breakpoint callback. That's described here:
http://lldb.llvm.org/python-reference.html
in the section on "Running a Python Script when a breakpoint gets hit".
One thing you'll find in the docs is that if the callback returns False, then lldb won't stop for that breakpoint hit.
Also, one of the arguments passed to the callback is the frame containing the code that just hit the breakpoint. The frame object is actually an lldb.SBFrame object. The docs for SBFrame are here:
http://lldb.llvm.org/python_reference/lldb.SBFrame-class.html
The parent
property of SBFrame returns the caller frame. The name
property returns the function name. So you want to do something like:
def MyCallback(frame, bp_loc, dict):
if frame.parent.name == "rb_ary_collect_bang":
return True
else
return False
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%2f53272632%2fhow-to-set-a-breakpoint-that-only-triggers-when-within-a-specific-parent-functio%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
As a follow up to Jim's answer, this can also be done as a one liner, without creating a named function:
breakpoint command add -s python -o 'return frame.parent.name == "rb_ary_collect_bang"'
lldb creates a wrapper function for you (which has a frame
parameter), and the key is to return
the result of the comparison, because as Jim said, lldb will stop if the result is true, and keep going if the result is false.
This can be extended to looking at any calling function in the stack:
br c add -s python -o 'return any(f.name == "rb_ary_collect_bang" for f in frame.thread)'
This one is a bit more opaque. The expression frame.thread
is an iterator of all frames on the current thread's stack. The expression [f.name for f in frame.thread]
would give you a list of all function names on the stack. The expression any(f.name == "abc" for f in frame.thread)
returns true if the function "abc" is anywhere in the stack.
GDB has some helper functions for these cases, and I wrote a similar set functions for lldb. https://github.com/kastiglione/lldb-helpers. Using these functions you could write:
break com add -F 'caller_is("rb_ary_collect_bang")'
add a comment |
As a follow up to Jim's answer, this can also be done as a one liner, without creating a named function:
breakpoint command add -s python -o 'return frame.parent.name == "rb_ary_collect_bang"'
lldb creates a wrapper function for you (which has a frame
parameter), and the key is to return
the result of the comparison, because as Jim said, lldb will stop if the result is true, and keep going if the result is false.
This can be extended to looking at any calling function in the stack:
br c add -s python -o 'return any(f.name == "rb_ary_collect_bang" for f in frame.thread)'
This one is a bit more opaque. The expression frame.thread
is an iterator of all frames on the current thread's stack. The expression [f.name for f in frame.thread]
would give you a list of all function names on the stack. The expression any(f.name == "abc" for f in frame.thread)
returns true if the function "abc" is anywhere in the stack.
GDB has some helper functions for these cases, and I wrote a similar set functions for lldb. https://github.com/kastiglione/lldb-helpers. Using these functions you could write:
break com add -F 'caller_is("rb_ary_collect_bang")'
add a comment |
As a follow up to Jim's answer, this can also be done as a one liner, without creating a named function:
breakpoint command add -s python -o 'return frame.parent.name == "rb_ary_collect_bang"'
lldb creates a wrapper function for you (which has a frame
parameter), and the key is to return
the result of the comparison, because as Jim said, lldb will stop if the result is true, and keep going if the result is false.
This can be extended to looking at any calling function in the stack:
br c add -s python -o 'return any(f.name == "rb_ary_collect_bang" for f in frame.thread)'
This one is a bit more opaque. The expression frame.thread
is an iterator of all frames on the current thread's stack. The expression [f.name for f in frame.thread]
would give you a list of all function names on the stack. The expression any(f.name == "abc" for f in frame.thread)
returns true if the function "abc" is anywhere in the stack.
GDB has some helper functions for these cases, and I wrote a similar set functions for lldb. https://github.com/kastiglione/lldb-helpers. Using these functions you could write:
break com add -F 'caller_is("rb_ary_collect_bang")'
As a follow up to Jim's answer, this can also be done as a one liner, without creating a named function:
breakpoint command add -s python -o 'return frame.parent.name == "rb_ary_collect_bang"'
lldb creates a wrapper function for you (which has a frame
parameter), and the key is to return
the result of the comparison, because as Jim said, lldb will stop if the result is true, and keep going if the result is false.
This can be extended to looking at any calling function in the stack:
br c add -s python -o 'return any(f.name == "rb_ary_collect_bang" for f in frame.thread)'
This one is a bit more opaque. The expression frame.thread
is an iterator of all frames on the current thread's stack. The expression [f.name for f in frame.thread]
would give you a list of all function names on the stack. The expression any(f.name == "abc" for f in frame.thread)
returns true if the function "abc" is anywhere in the stack.
GDB has some helper functions for these cases, and I wrote a similar set functions for lldb. https://github.com/kastiglione/lldb-helpers. Using these functions you could write:
break com add -F 'caller_is("rb_ary_collect_bang")'
answered Dec 5 '18 at 19:23
Dave LeeDave Lee
4,7322631
4,7322631
add a comment |
add a comment |
You need to write a Python breakpoint callback. That's described here:
http://lldb.llvm.org/python-reference.html
in the section on "Running a Python Script when a breakpoint gets hit".
One thing you'll find in the docs is that if the callback returns False, then lldb won't stop for that breakpoint hit.
Also, one of the arguments passed to the callback is the frame containing the code that just hit the breakpoint. The frame object is actually an lldb.SBFrame object. The docs for SBFrame are here:
http://lldb.llvm.org/python_reference/lldb.SBFrame-class.html
The parent
property of SBFrame returns the caller frame. The name
property returns the function name. So you want to do something like:
def MyCallback(frame, bp_loc, dict):
if frame.parent.name == "rb_ary_collect_bang":
return True
else
return False
add a comment |
You need to write a Python breakpoint callback. That's described here:
http://lldb.llvm.org/python-reference.html
in the section on "Running a Python Script when a breakpoint gets hit".
One thing you'll find in the docs is that if the callback returns False, then lldb won't stop for that breakpoint hit.
Also, one of the arguments passed to the callback is the frame containing the code that just hit the breakpoint. The frame object is actually an lldb.SBFrame object. The docs for SBFrame are here:
http://lldb.llvm.org/python_reference/lldb.SBFrame-class.html
The parent
property of SBFrame returns the caller frame. The name
property returns the function name. So you want to do something like:
def MyCallback(frame, bp_loc, dict):
if frame.parent.name == "rb_ary_collect_bang":
return True
else
return False
add a comment |
You need to write a Python breakpoint callback. That's described here:
http://lldb.llvm.org/python-reference.html
in the section on "Running a Python Script when a breakpoint gets hit".
One thing you'll find in the docs is that if the callback returns False, then lldb won't stop for that breakpoint hit.
Also, one of the arguments passed to the callback is the frame containing the code that just hit the breakpoint. The frame object is actually an lldb.SBFrame object. The docs for SBFrame are here:
http://lldb.llvm.org/python_reference/lldb.SBFrame-class.html
The parent
property of SBFrame returns the caller frame. The name
property returns the function name. So you want to do something like:
def MyCallback(frame, bp_loc, dict):
if frame.parent.name == "rb_ary_collect_bang":
return True
else
return False
You need to write a Python breakpoint callback. That's described here:
http://lldb.llvm.org/python-reference.html
in the section on "Running a Python Script when a breakpoint gets hit".
One thing you'll find in the docs is that if the callback returns False, then lldb won't stop for that breakpoint hit.
Also, one of the arguments passed to the callback is the frame containing the code that just hit the breakpoint. The frame object is actually an lldb.SBFrame object. The docs for SBFrame are here:
http://lldb.llvm.org/python_reference/lldb.SBFrame-class.html
The parent
property of SBFrame returns the caller frame. The name
property returns the function name. So you want to do something like:
def MyCallback(frame, bp_loc, dict):
if frame.parent.name == "rb_ary_collect_bang":
return True
else
return False
answered Nov 13 '18 at 20:53
Jim InghamJim Ingham
13.7k13034
13.7k13034
add a comment |
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.
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%2f53272632%2fhow-to-set-a-breakpoint-that-only-triggers-when-within-a-specific-parent-functio%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