{"id":325,"date":"2010-10-20T13:10:20","date_gmt":"2010-10-20T18:10:20","guid":{"rendered":"http:\/\/www.jaimerios.com\/?p=325"},"modified":"2010-10-20T13:10:20","modified_gmt":"2010-10-20T18:10:20","slug":"getting-gdb-to-stop-on-a-conditional-breakpoint","status":"publish","type":"post","link":"https:\/\/jaimerios.com\/?p=325","title":{"rendered":"Getting GDB to stop on a conditional breakpoint"},"content":{"rendered":"<p>One of the cool things about Xcode and GDB is that you can create custom breakpoints that could be set up by calling a function within your own project.<\/p>\n<p>GDB supports C functionality in their conditional checks, but for me, I found this functionality to be particularly helpful when paired with convenience variables.<\/p>\n<p>So, let&#8217;s say you have a string in your function and you want your breakpoint to only be triggered when the string matches a particular pattern. What you could do is the following:<\/p>\n<ol>\n<li>Set up a convenience variable and set that to the result of a strstr call<\/li>\n<li>Create another breakpoint where it breaks on the new convenience variable<\/li>\n<\/ol>\n<p>In a breakpoint, set the following in the command:<br \/>\nset $myRes = (char*)strstr(myCharPtr, &#8220;My search string&#8221;)<\/p>\n<p>For this particular breakpoint, you can actually set it to continue since you don&#8217;t want to stop every time GDB gets to that point.<\/p>\n<p>Now in a new breakpoint, set the condition for that breakpoint to $myRes<\/p>\n<p>One problem I see with this is that you might break on a line of code that doesn&#8217;t make sense if the same variable was modified by another thread.<\/p>\n<p>In this case, you might want to reset the variable or have another condition to check the thread id too!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the cool things about Xcode and GDB is that you can create custom breakpoints that could be set up by calling a function within your own project. GDB supports C functionality in their conditional checks, but for me, I found this functionality to be particularly helpful when paired with convenience variables. So, let&#8217;s &#8230; <a title=\"Getting GDB to stop on a conditional breakpoint\" class=\"read-more\" href=\"https:\/\/jaimerios.com\/?p=325\" aria-label=\"Read more about Getting GDB to stop on a conditional breakpoint\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[132,212,506],"class_list":["post-325","post","type-post","status-publish","format-standard","hentry","category-coding","tag-conditional-breakpoints","tag-gdb","tag-xcode"],"_links":{"self":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/posts\/325","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=325"}],"version-history":[{"count":0,"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/posts\/325\/revisions"}],"wp:attachment":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=325"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=325"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=325"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}