{"id":17968672,"url":"https://github.com/david942j/gdb-ruby","last_synced_at":"2025-03-25T10:32:31.462Z","repository":{"id":25474736,"uuid":"104097838","full_name":"david942j/gdb-ruby","owner":"david942j","description":"It's time for Ruby lovers to use Ruby in gdb, and gdb in Ruby!","archived":false,"fork":false,"pushed_at":"2023-01-09T21:03:31.000Z","size":109,"stargazers_count":64,"open_issues_count":3,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-20T01:07:00.383Z","etag":null,"topics":["gdb","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/david942j.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-19T16:11:29.000Z","updated_at":"2024-11-16T17:22:07.000Z","dependencies_parsed_at":"2023-01-14T02:48:08.640Z","dependency_job_id":null,"html_url":"https://github.com/david942j/gdb-ruby","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/david942j%2Fgdb-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/david942j%2Fgdb-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/david942j%2Fgdb-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/david942j%2Fgdb-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/david942j","download_url":"https://codeload.github.com/david942j/gdb-ruby/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245444348,"owners_count":20616364,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gdb","ruby"],"created_at":"2024-10-29T14:41:13.553Z","updated_at":"2025-03-25T10:32:29.516Z","avatar_url":"https://github.com/david942j.png","language":"Ruby","readme":"[![Build Status](https://github.com/david942j/gdb-ruby/workflows/build/badge.svg)](https://github.com/david942j/gdb-ruby/actions)\n[![Gem Version](https://badge.fury.io/rb/gdb.svg)](https://badge.fury.io/rb/gdb)\n[![Code Climate](https://codeclimate.com/github/david942j/gdb-ruby/badges/gpa.svg)](https://codeclimate.com/github/david942j/gdb-ruby)\n[![Issue Count](https://codeclimate.com/github/david942j/gdb-ruby/badges/issue_count.svg)](https://codeclimate.com/github/david942j/gdb-ruby)\n[![Test Coverage](https://codeclimate.com/github/david942j/gdb-ruby/badges/coverage.svg)](https://codeclimate.com/github/david942j/gdb-ruby/coverage)\n[![Inline docs](https://inch-ci.org/github/david942j/gdb-ruby.svg?branch=master)](https://inch-ci.org/github/david942j/gdb-ruby)\n[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](http://choosealicense.com/licenses/mit/)\n\n# GDB-Ruby\n\nIt's time for Ruby lovers to use Ruby in gdb and gdb in Ruby!\n\nAchieve two things in one gem:\n\n1. Launching Ruby interactive shell (pry) in gdb.\n2. gdb Ruby-binding, i.e. communicate with gdb in Ruby scripts.\n\n# Use Ruby in gdb\n\nWe provide a binary `gdb-ruby` (a Ruby script actually) with usage exactly the same as a normal gdb,\nwhile has two extra commands: `ruby` and `pry`!\n\nSee examples below:\n\n```yaml\n$ gdb-ruby -q bash\nReading symbols from bash...(no debugging symbols found)...done.\n(gdb) help ruby\nEvaluate a Ruby command.\nThere's an instance 'gdb' for you. See examples.\n\nSyntax: ruby \u003cruby code\u003e\n\nExamples:\n    ruby p 'abcd'\n    # \"abcd\"\n\nUse gdb:\n    ruby puts gdb.break('main')\n    # Breakpoint 1 at 0x41eed0\n\nMethod defined will remain in context:\n    ruby def a(b); b * b; end\n    ruby p a(9)\n    # 81\n(gdb) help pry\nEnter Ruby interactive shell.\nEverything works like a charm!\n\nSyntax: pry\n\nExample:\n    pry\n    # [1] pry(#\u003cGDB::EvalContext\u003e)\u003e\n```\n\n## Integrate with other gdb extensions\n\nCompletely *NO* effort if you want to use **gdb-ruby** with other gdb extensions.\n\nFor example, I usually use the plugin [gef](https://github.com/hugsy/gef) with gdb.\nEverything works as usual when integrated with **gdb-ruby**:\n\nLaunching with `$ gdb-ruby -q bash`\n\n![ruby-in-gef](https://i.imgur.com/W8biCgP.png)\n\n# Use gdb in Ruby\n\nCommunicate with gdb in your Ruby script.\n\n## Useful methods\n\nBasic usage is use `execute` to do anything you want to execute inside gdb,\nwhile **gdb-ruby** provides some useful methods listed as following:\n\n* `break`: Set break points. Alias: `b`\n* `run`: Run. Alias: `r`\n* `register`: Get value by register's name. Alias: `reg`\n* `text_base`: Get current running program's text base, useful for a PIE binary.\n* `pid`: Get the process id of running process.\n* `read_memory`: Read process's memory, with friendly type casting. Alias: `readm`\n* `write_memory`: Write process's memory, useful for dynamic analysis. Alias: `writem`\n* `interact`: Back to normal gdb interactive mode.\n\nAll of these methods are fully documented at [online doc](http://www.rubydoc.info/github/david942j/gdb-ruby/master/GDB/GDB), go for it!\n\n## Examples\n\nPlay with argv using **gdb-ruby**.\n\nThis script does:\n1. Set a break point at `main`.\n2. Get argv using `register` and `read_memory`.\n3. Change argv using `write_memory`.\n\n```ruby\nrequire 'gdb'\n\n# launch a gdb instance\ngdb = GDB::GDB.new('bash')\n\n# 1. set breakpoint\ngdb.break('main')\n#=\u003e \"Breakpoint 1 at 0x41eed0\"\ngdb.run('-c \"echo cat\"')\n\n# 2. get argv pointers\nrdi = gdb.reg(:rdi)\n#=\u003e 3\nrsi = gdb.reg(:rsi)\nargv = gdb.readm(rsi, rdi, as: :u64)\nargv.map { |c| '0x%x' % c }\n#=\u003e ['0x7fffffffe61b', '0x7fffffffe625', '0x7fffffffe628']\n\n# 3. overwrite argv[2]'s 'cat' to 'FAT'\ngdb.writem(argv[2] + 5, 'FAT') # echo FAT\n\nputs gdb.execute('continue')\n# Continuing.\n# FAT\n# [Inferior 1 (process 32217) exited normally]\n```\n\nSet a break point, run it, and back to gdb interactive mode.\n\n```ruby\nrequire 'gdb'\n\n# launch a gdb instance\ngdb = GDB::GDB.new('bash')\n# set breakpoints\ngdb.break('main')\ngdb.run\n# to show the process do stop at the breakpoint\ngdb.execute('info reg rip')\n#=\u003e \"rip            0x41eed0\\t0x41eed0 \u003cmain\u003e\"\n\n# interaction like normal gdb!\ngdb.interact\n```\n\n# Installation\n\nAvailable on RubyGems.org!\n\n```\n$ gem install gdb\n```\n\n# Development\n\n```\ngit clone https://github.com/david942j/gdb-ruby\ncd gdb-ruby\nbundle\nbundle exec rake\n```\n\n# Bugs \u0026 Feedback\n\nFeel free to file an issue if you find any bugs.\nAny feature requests and suggestions are welcome! :grimacing:\n\n# Growing up\n\n**gdb-ruby** is under developing, give it a star and [watch](https://github.com/david942j/gdb-ruby/subscription)\nfor latest updates!\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavid942j%2Fgdb-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavid942j%2Fgdb-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavid942j%2Fgdb-ruby/lists"}