This blog describes anything about @mrkn's thoughts, which includes computer programming (mostly Ruby, Haskell, and C++), mathematics, physics, and so on. Each article is written in English for learning it.


To use preprocessor macros on gdb

When debugging ruby on gdb, we often want to expand some preprocessor macros, such as RSTRING_LEN, RARRAY_PTR. To make preprocessor macros available to gdb, we should call gcc with these debugging options: -gdwarf-2 -g3.

To configure ruby with these options, we do,

./configure debugflags="-gdwarf-2 -g3"

Then build ruby,


This allows us to expand preprocessor macros in gdb like this:

$ gdb --quiet /opt/ruby/trunk/bin/ruby
Reading symbols for shared libraries .... done
(gdb) b ruby_yyparse 
Breakpoint 1 at 0x20c49ba5cd1c8b: file parse.c, line 4583.
(gdb) r
Starting program: /opt/ruby/trunk/bin/ruby 
Reading symbols for shared libraries +++... done
Reading symbols for shared libraries . done

Breakpoint 1, ruby_yyparse (parser=0x10060c310) at parse.c:4583
4583    {
(gdb) macro expand Qfalse
expands to: ((VALUE)RUBY_Qfalse)
(gdb) info macro RSTRING_PTR
Defined at ../include/ruby/ruby.h:619
  included at /Users/muraken/src/ruby.git/build-osx/parse.c:18
#define RSTRING_PTR(str) (!(RBASIC(str)->flags & RSTRING_NOEMBED) ? RSTRING(str)->as.ary : RSTRING(str)->as.heap.ptr)

Note that we must be in a frame where the target preprocessor macros are visible.

I thank hayeah and ujihisa for helpful discussion about this topic and proofreading my English.

See also:


  1. Thanks, this info was exactly what I needed.

  2. Outstanding post and wonderful blog, I really like of interesting articles keep it

  3. You did good work your placement is breathtaking its augment my information. do coursework uk

  4. I enjoy it for creating the details, keep up the truly amazing perform continuing

  5. I believe working on these micros can fix lot of problems in the coding. Thanks for sharing a perfect solution. Dissertation writing services UK

  6. , thanks you for sharing with us. This is nice blogs PLease visit profile picture

  7. Nice post. I was checking constantly this blog and I am impressed! Extremely helpful information specially the last part I care for such info a lot. I was seeking this particular information for a very long time. Thank you and good luck. instagram web viewer

  8. Your blog provided us with valuable information to work with. Each & every tips of your post are awesome. Thanks a lot for sharing. Keep blogging, tokyo olimpics 2020

  9. You’re a very skilled blogger. I have joined your feed and look forward to seeking more of your fantastic post. I wanted help with that. Dissertation Writing Services suggest by a companion was an excellent deal