How to set a breakpoint that only triggers when within a specific parent function?












0















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.










share|improve this question



























    0















    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.










    share|improve this question

























      0












      0








      0








      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.










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 '18 at 1:50









      ioquatixioquatix

      882922




      882922
























          2 Answers
          2






          active

          oldest

          votes


















          2














          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")'





          share|improve this answer































            1














            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





            share|improve this answer























              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
              });


              }
              });














              draft saved

              draft discarded


















              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









              2














              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")'





              share|improve this answer




























                2














                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")'





                share|improve this answer


























                  2












                  2








                  2







                  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")'





                  share|improve this answer













                  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")'






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 5 '18 at 19:23









                  Dave LeeDave Lee

                  4,7322631




                  4,7322631

























                      1














                      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





                      share|improve this answer




























                        1














                        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





                        share|improve this answer


























                          1












                          1








                          1







                          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





                          share|improve this answer













                          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






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 13 '18 at 20:53









                          Jim InghamJim Ingham

                          13.7k13034




                          13.7k13034






























                              draft saved

                              draft discarded




















































                              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.




                              draft saved


                              draft discarded














                              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





















































                              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







                              Popular posts from this blog

                              Florida Star v. B. J. F.

                              Error while running script in elastic search , gateway timeout

                              Adding quotations to stringified JSON object values