# Getting a Debugger set up for Ruby

**URL:** <https://forums.sketchup.com/t/getting-a-debugger-set-up-for-ruby/103701>\
**Category:** Ruby API\
**Created:** [September 18, 2019, 8:13pm UTC](https://forums.sketchup.com/t/getting-a-debugger-set-up-for-ruby/103701 "2019-09-18T20:13:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![TommyK](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tommyk/32/2998_2.png) [@TommyK](https://forums.sketchup.com/u/TommyK)\
**Post date:** [September 18, 2019, 8:13pm UTC](https://forums.sketchup.com/t/getting-a-debugger-set-up-for-ruby/103701/1 "2019-09-18T20:13:47Z")

</div>

I am building a Ruby C Extension in XCode. It is working, but there are some annoying EXC\_BAD\_ACCESS errors that I am finding really difficult to see where it is coming from.

XCode debugger gives me just this information:

```
SketchUp`CComponentDefinition::GetInstance:
    0x1003cce9a <+0>: pushq %rbp
    0x1003cce9b <+1>: movq %rsp, %rbp
    0x1003cce9e <+4>: movslq %esi, %rax
    0x1003ccea1 <+7>: movq 0x378(%rdi), %rcx
-> 0x1003ccea8 <+14>: movq (%rcx,%rax,8), %rax CrBrowserMain (1): EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
    0x1003cceac <+18>: popq %rbp
    0x1003ccead <+19>: retq   

```

using lldb, I have done a backtrace with the following results (back to 15 frames only):

```
thread #1, name = 'CrBrowserMain', queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
  * frame #0: 0x00000001003ccea8 SketchUp`CComponentDefinition::GetInstance(int) + 14
    frame #1: 0x00000001004c96f9 SketchUp`___lldb_unnamed_symbol7166$$SketchUp + 86
    frame #2: 0x0000000100e01ebe Ruby`vm_call_cfunc + 302
    frame #3: 0x0000000100de7bed Ruby`vm_exec_core + 13725
    frame #4: 0x0000000100dfc19e Ruby`vm_exec + 142
    frame #5: 0x0000000100df1eef Ruby`rb_funcallv + 559
    frame #6: 0x000000010054f030 SketchUp`___lldb_unnamed_symbol8556$$SketchUp + 262
    frame #7: 0x0000000100c989b3 Ruby`rb_protect + 339
    frame #8: 0x000000010054eec2 SketchUp`protect_funcall(unsigned long, unsigned long, std:: __1::vector<unsigned long, std::__ 1::allocator<unsigned long> > const&) + 255
    frame #9: 0x000000010054ec76 SketchUp`protect_funcall(unsigned long, unsigned long, int, ...) + 305
    frame #10: 0x0000000100523b4a SketchUp`sketchup::api::ruby::NotificationQueue::DispatchNotification(sketchup::api::ruby::RubyApiNotification const&) + 152
    frame #11: 0x0000000100523cfc SketchUp`sketchup::api::ruby::NotificationQueue::Dispatch() + 152
    frame #12: 0x0000000101deceb0 libCommonUtils.dylib`CNotificationCenter::SendNotification(char const*, void*) + 278
    frame #13: 0x00000001003bc4ab SketchUp`sketchup::api::SendTransactionEnd() + 39
    frame #14: 0x000000010048ac74 SketchUp`CUndoManager::CommitCurrentOperation(unsigned int, bool) + 572
    frame #15: 0x00000001004f92c9 SketchUp`___lldb_unnamed_symbol7728$$SketchUp + 168

```

None of the debug information that I am getting is pointing to where in _my_ code the error is coming from. I know it is coming from my code, most likely in my ruby code, as the C errors are proving much easier to debug.

My first questions is, with errors like these, is there a debugging solution that I should be aware of? I have noticed that the XCode breakpoints in my ruby scripts don’t seem to work - the only debugging information I can get from Ruby are custom messages output with `puts`, and some of the common Exception Errors that the Sketchup Ruby API put out.

If the answer to the above is “yes”, then where do you recommend I look? I’ve looked at these topics without much luck on my part:

> [@The right choice of a Ruby debugger for Sketchup API](https://forums.sketchup.com/t/the-right-choice-of-a-ruby-debugger-for-sketchup-api/76490/2):
>
> A code editor is not a debugger. Not all editors can interface with a debugger, but most IDEs can. This is the only debugger that will work with SketchUp. There are some IDEs listed in the README file …

> **[GitHub - SketchUp/sketchup-ruby-debugger: Ruby API debugger for SketchUp 2014...](https://github.com/SketchUp/sketchup-ruby-debugger)**
>
> Ruby API debugger for SketchUp 2014 and later. Contribute to SketchUp/sketchup-ruby-debugger development by creating an account on GitHub.

…maybe I just need to go RubyMine:?

> [@Please help me to setup debugger on RubyMine for Mac](https://forums.sketchup.com/t/please-help-me-to-setup-debugger-on-rubymine-for-mac/289/6):
>
> What code is that? The VBS? That can be anywhere - just give the full path to it.

Many thanks

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [September 18, 2019, 8:43pm UTC](https://forums.sketchup.com/t/getting-a-debugger-set-up-for-ruby/103701/2 "2019-09-18T20:43:28Z")

</div>

> [@TommyK](#):
>
> My first questions is, with errors like these, is there a debugging solution that I should be aware of?

Saw this …

- [Is EXC\_BAD\_ACCESS and How to Debug It - Code Tuts](https://code.tutsplus.com/tutorials/what-is-exc_bad_access-and-how-to-debug-it--cms-24544)  
_At one point or another, you will run into a crash caused by **EXC\_BAD\_ACCESS**. In this quick tip, you will learn what EXC\_BAD\_ACCESS is and what it is caused by. I will also give you a few tips to fix bugs that are caused by EXC\_BAD\_ACCESS._

… via a [Google Search on: “EXC\_I386\_GPFLT”](https://www.google.com/search?q=EXC_I386_GPFLT)

I don’t code for Mac but it sounds like the author knows what they’re talking about.

---

<div class="post-metadata">

**Author:** ![john\_drivenupthewall](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@john\_drivenupthewall](https://forums.sketchup.com/u/john_drivenupthewall)\
**Post date:** [September 18, 2019, 9:18pm UTC](https://forums.sketchup.com/t/getting-a-debugger-set-up-for-ruby/103701/3 "2019-09-18T21:18:44Z")

</div>

`CrBrowserMain` references Chrome Browser embedded in SU.

it’s been causing odd issues on mac since day one…

you may need to point to it in Xcode or maybe turn off anything that uses it DC, TC…

john

---

<div class="post-metadata">

**Author:** ![TommyK](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tommyk/32/2998_2.png) [@TommyK](https://forums.sketchup.com/u/TommyK)\
**Post date:** [September 18, 2019, 9:36pm UTC](https://forums.sketchup.com/t/getting-a-debugger-set-up-for-ruby/103701/4 "2019-09-18T21:36:16Z")

</div>

> [@DanRathbun](#):
>
> Saw this …
> 
> - [Is EXC\_BAD\_ACCESS and How to Debug It - Code Tuts](https://code.tutsplus.com/tutorials/what-is-exc_bad_access-and-how-to-debug-it--cms-24544)  
> _At one point or another, you will run into a crash caused by **EXC\_BAD\_ACCESS**. In this quick tip, you will learn what EXC\_BAD\_ACCESS is and what it is caused by. I will also give you a few tips to fix bugs that are caused by EXC\_BAD\_ACCESS._
> 
> … via a [Google Search on: “EXC\_I386\_GPFLT”](https://www.google.com/search?q=EXC_I386_GPFLT)
> 
> I don’t code for Mac but it sounds like the author knows what they’re talking about.

Yes, that page did help me in my early experiences with the error. However, it is limited with my particular case, where the EXC\_BAD\_ACCESS is happening deep within Sketchup’s own functions.

> [@john\_drivenupthewall](#):
>
> `CrBrowserMain` references Chrome Browser embedded in SU.
> 
> it’s been causing odd issues on mac since day one…
> 
> you may need to point to it in Xcode or maybe turn off anything that uses it DC, TC…

That’s a good tip. I was wondering what a Chrome Browser was doing in there - DC maybe the issue…

---

<div class="post-metadata">

**Author:** ![TommyK](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tommyk/32/2998_2.png) [@TommyK](https://forums.sketchup.com/u/TommyK)\
**Post date:** [September 20, 2019, 4:31pm UTC](https://forums.sketchup.com/t/getting-a-debugger-set-up-for-ruby/103701/5 "2019-09-20T16:31:50Z")

</div>

To answer my own question. I found that using the ruby debugger on lldb allowed me to do backtraces when things went wrong.

This article tells you how it’s done:  
[https://christoph.luppri.ch/articles/ruby/debugging-ruby-programs-on-osx-with-lldb/](https://christoph.luppri.ch/articles/ruby/debugging-ruby-programs-on-osx-with-lldb/)

---

<div class="post-metadata">

**Author:** ![tt\_su](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tt_su/32/17_2.png) [@tt\_su](https://forums.sketchup.com/u/tt_su)\
**Post date:** [October 2, 2019, 1:26pm UTC](https://forums.sketchup.com/t/getting-a-debugger-set-up-for-ruby/103701/6 "2019-10-02T13:26:32Z")

</div>

> [@TommyK](#):
>
> None of the debug information that I am getting is pointing to where in _my_ code the error is coming from. I know it is coming from my code, most likely in my ruby code, as the C errors are proving much easier to debug.

When working with Ruby C Extensions it can be challenging to debug since the Ruby Debugger only works for .rb sources and your C/C++ debugger won’t give you all Ruby info you need.

> [@TommyK](#):
>
> …maybe I just need to go RubyMine:?

I find VSCode easier and faster to set up. (And it’s free.)

> **[GitHub - SketchUp/sketchup-extension-vscode-project: VSCode Project for...](https://github.com/SketchUp/sketchup-extension-vscode-project)**
>
> VSCode Project for SketchUp Extension Development. Contribute to SketchUp/sketchup-extension-vscode-project development by creating an account on GitHub.

> [@TommyK](#):
>
> To answer my own question. I found that using the ruby debugger on lldb allowed me to do backtraces when things went wrong.

Oh, that’s interesting! Probably not something that would work on Windows though… (?)

---

<div class="post-metadata">

**Author:** ![tt\_su](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tt_su/32/17_2.png) [@tt\_su](https://forums.sketchup.com/u/tt_su)\
**Post date:** [October 2, 2019, 2:45pm UTC](https://forums.sketchup.com/t/getting-a-debugger-set-up-for-ruby/103701/7 "2019-10-02T14:45:57Z")

</div>

Actually, reading this closer - it looks like it sets up `lldb` to be able to eval Ruby code while debugging to inspect Ruby data. But that’s so much easier to do with the Ruby debugger gem: [GitHub - ruby-debug/ruby-debug-ide: An interface which glues ruby-debug to IDEs like Eclipse (RDT), NetBeans and RubyMine.](https://github.com/ruby-debug/ruby-debug-ide)

I’d originally thought it was to aid in Ruby C extension territory.

---

<div class="post-metadata">

**Author:** ![TommyK](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tommyk/32/2998_2.png) [@TommyK](https://forums.sketchup.com/u/TommyK)\
**Post date:** [October 2, 2019, 3:41pm UTC](https://forums.sketchup.com/t/getting-a-debugger-set-up-for-ruby/103701/8 "2019-10-02T15:41:03Z")

</div>

That’s a good tip. Will try to get that running.

As an update, I am actually resolved that the error was in fact in the dynamic components extension (after one of my observer callbacks).
