133 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto 66f438d8fe mruby-bin-debugger: return on OOM in mrb_debug_set_break_method
mrb_debug_set_break_method() freed set_class after mrdb_strdup() of
method_name failed but did not return. Execution continued into
alloc_breakpoint(), which on failure double-freed set_class, or on
success stored the dangling pointer in the breakpoint table for later
use-after-free. Return MRB_DEBUG_NOBUF immediately after the free.

mrdb_strdup uses mrb_malloc_simple which returns NULL on OOM (it does
not raise), so the NULL check is reachable in practice.

close #6851

Co-authored-by: Claude <noreply@anthropic.com>
2026-05-22 07:08:26 +09:00
dearblue 0d00743a5f Define the typedef for mrb_state earlier
This improves consistency with other definitions.
2026-04-19 21:17:18 +09:00
Yukihiro "Matz" Matsumoto 8956c5abb5 mruby.h: include mruby/presym.h for all source files
Since presym is now mandatory, mruby.h includes presym.h so that
MRB_SYM() macros are available everywhere without explicit include.
Remove redundant #include <mruby/presym.h> from all source files.

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-09 16:50:58 +09:00
Yukihiro "Matz" Matsumoto b9007a8f0a cmdprint.c: extract next_print_no() helper
Consolidate the duplicated print_no increment-and-wrap logic
from dbgcmd_print() and dbgcmd_info_local() into a single
next_print_no() function.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-24 09:05:02 +09:00
Yukihiro "Matz" Matsumoto d3dfe83aa1 apibreak.c: simplify get_break_index()
Return directly from the loop instead of using a hit flag
and separate index variable.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-24 09:04:25 +09:00
Yukihiro "Matz" Matsumoto e35c011537 cmdmisc.c: extract parse_file_line_spec() from parse_listcmd_args()
Flatten 4-level nested parsing of list command arguments into
a separate parse_file_line_spec() function.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-24 09:03:59 +09:00
Yukihiro "Matz" Matsumoto 1d52c7a3dd mrdb.c: extract check_breakpoint_hit() from mrb_code_fetch_hook()
Combine method and line breakpoint checks into a single
check_breakpoint_hit() helper, simplifying the DBG_RUN case.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-24 09:03:28 +09:00
Yukihiro "Matz" Matsumoto 8702244a42 mrdb.c: decompose parse_command() into lookup helpers
Extract find_command_by_word1() and find_command_by_words()
from parse_command(), separating command-table lookup from
tokenization logic.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-24 09:02:47 +09:00
Yukihiro "Matz" Matsumoto eedc95460c mruby-bin-debugger: extract raise_debugger_exception() helper
Both dbgcmd_run() and dbgcmd_quit() defined an exception class
and raised it with identical code. Add a shared static inline
helper in mrdb.h.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-24 09:02:11 +09:00
Yukihiro "Matz" Matsumoto 811741eb8e cmdbreak.c: unify delete/enable/disable via dbgcmd_set_breakpoint()
The three commands shared identical dispatch logic. Extract a
shared dbgcmd_set_breakpoint() that takes function pointers,
reducing each command to a one-line wrapper.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-24 09:01:19 +09:00
Yukihiro "Matz" Matsumoto 2c21e1a959 apibreak.c: extract alloc_breakpoint() helper
Extract common breakpoint slot allocation logic from
mrb_debug_set_break_line() and mrb_debug_set_break_method()
into a shared alloc_breakpoint() helper.

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-24 09:00:49 +09:00
John Bampton 12b128bf43 docs: fix pre-commit manual hooks; fix link
Ran `pre-commit run --all-files --hook-stage manual` and this ran prettier.

We had a Markdown table reformated and an backslash escape added.

A link was also fixed.

Tested both the standard and manual hooks pass
2025-12-28 20:28:00 +10:00
Yukihiro "Matz" Matsumoto 9ad72e3a96 mrbgems: add README documentation for mruby-bin-* gems
- mruby-bin-config
- mruby-bin-debugger
- mruby-bin-mrbc
- mruby-bin-mruby
- mruby-bin-strip

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-11 18:09:10 +09:00
Yukihiro "Matz" Matsumoto 40b0cb98f7 mruby.h: add MRB_OPEN_FAILURE() macro and refactor MRB_OPEN_SUCCESS()
since all current uses check for failure (!MRB_OPEN_SUCCESS), add
MRB_OPEN_FAILURE() as the primary macro for better readability. define
MRB_OPEN_SUCCESS() in terms of MRB_OPEN_FAILURE() to avoid duplication
and optimize the common case. update all usage sites to use the clearer
MRB_OPEN_FAILURE() form.

Co-authored-by: Claude <noreply@anthropic.com>
2025-11-16 06:53:02 +09:00
Yukihiro "Matz" Matsumoto 8e50a45f3e mrb_print_error: handle NULL gracefully to simplify error checking
made mrb_print_error() handle NULL by printing "Failed to allocate
mrb_state" when mrb is NULL. since mrb_close() already handles NULL,
this allows simplified error checking pattern:

  if (!MRB_OPEN_SUCCESS(mrb)) {
    mrb_print_error(mrb);  // handles NULL
    mrb_close(mrb);        // handles NULL
    return EXIT_FAILURE;
  }

updated all binary tools (mruby, mirb, mrdb, mrbtest) to use this
simplified pattern, removing nested if checks.

Co-authored-by: Claude <noreply@anthropic.com>
2025-11-14 00:49:55 +09:00
Yukihiro "Matz" Matsumoto 05ffe0c441 mrb_open: return mrb_state with exc set on init failure
changed mrb_open() and mrb_open_core() to return mrb_state with mrb->exc
set (instead of NULL) when initialization fails. this allows callers to
programmatically inspect error details, which is essential for embedded
systems without stderr. return NULL only for true allocation failure.

added MRB_OPEN_SUCCESS(mrb) macro to check initialization success, since
mrb != NULL no longer guarantees success. updated all binary tools
(mruby, mirb, mrdb, mrbtest) to use new pattern: check MRB_OPEN_SUCCESS,
print exception details via mrb_print_error if available, then mrb_close.

mrb_core_init_protect now preserves exception in mrb->exc instead of
printing and clearing it, giving caller control over error handling.

breaking change: callers must use MRB_OPEN_SUCCESS(mrb) or check both
mrb != NULL && mrb->exc == NULL. old NULL-only checks will miss
initialization failures.

Co-authored-by: Claude <noreply@anthropic.com>
2025-11-13 19:10:46 +09:00
Yukihiro "Matz" Matsumoto d8496fc9be mruby-bin-debugger: combine variable declaration with initialization 2025-11-08 14:30:13 +09:00
Yukihiro "Matz" Matsumoto cd5b9fff58 Merge pull request #6568 from dearblue/debugger1 2025-07-05 16:49:26 +09:00
dearblue 2f61e0b958 sed s/Mruby/MRuby/g
For name consistency.
2025-07-01 20:57:52 +09:00
dearblue 9053c79c3c mruby-bin-debugger depends on mruby-bin-mrbc in bintest 2025-07-01 20:51:11 +09:00
Yukihiro "Matz" Matsumoto 81f5f5b8d4 mruby-bin-debugger: should not use Exception#inspect to print errors
Use mrb_exc_get_output() instead.
2025-05-07 12:34:13 +09:00
Yukihiro "Matz" Matsumoto 6037e50298 test/hash: update tests to new hash format 2024-12-21 08:53:57 +09:00
Yukihiro "Matz" Matsumoto 5387b74be7 hash.c (mrb_hash_to_s): put spaces around =>
CRuby 3.4 puts spaces around `=>` since for example `{:a!=>2}` can be
confusing where to separate tokens.  mruby should follow the behavior.

Many tests in `test/t` directory assumed no spaces around `=>`, so we
needed to fix them too.
2024-11-11 11:07:43 +09:00
John Bampton de8a6fe787 Fix spelling 2024-07-13 00:21:53 +10:00
dearblue 8dfebe8d12 Need to synchronize dbg->regs after VM call in mrdb
VM inrush could invalidate addresses stored in `dbg->regs` by `stack_extend()`.
2024-03-31 11:53:09 +09:00
Yukihiro "Matz" Matsumoto 87b358a342 Including header files in include/* by <> 2024-03-26 13:59:59 +09:00
Yukihiro "Matz" Matsumoto c36b212fa9 mruby-bin-debugger: replace mrbc_ prefix by mrb_ccontext 2023-12-06 15:41:15 +09:00
Yukihiro "Matz" Matsumoto a66c685c81 mruby-bin-debugger/mrdb.h: remove unnecessary struct declarations 2023-12-06 15:40:31 +09:00
Yukihiro "Matz" Matsumoto 89f7bb1056 use more lightweight mrb_funcall_argv instead of mrb_funcall_id 2023-06-12 14:22:04 +09:00
Yukihiro "Matz" Matsumoto 39a29a7de1 mruby-bin-debugger/mrbgem.rake: fix defines configuration
`spec.build.defines` should be update inline. Otherwise, configuration
may differ from file to file.
2023-06-12 13:07:57 +09:00
Yukihiro "Matz" Matsumoto 2f7f797473 remove extra spaces before ; 2023-05-22 12:05:35 +09:00
Yukihiro "Matz" Matsumoto 6a6c0869dc add a space between for and ( 2023-05-22 11:58:23 +09:00
Yukihiro "Matz" Matsumoto eea72ec84a fix spaces in the type cast expressions (cosmetic changes) 2023-05-18 23:29:16 +09:00
Yukihiro "Matz" Matsumoto b4c936b533 use new E_EXCEPTION and E_STANDARD_ERROR; ref #5924 2023-02-10 15:21:38 +09:00
Yukihiro "Matz" Matsumoto b99c389ec3 internal.h: aggregate internal functions.
Internal functions can only be called from within the library.
Functions listed in `mruby/internal.h` can be called from:

* core (src/*.c)
* gems (mrbgems/**/*.c)

But not from the application linked with `libmruby`.
2022-04-02 18:25:13 +09:00
Yukihiro "Matz" Matsumoto d6dd6f0e7b Update struct initializer to work with relatively older C++. 2021-09-20 19:13:17 +09:00
Yukihiro "Matz" Matsumoto 8619ba6a38 Use struct initializer instead of memset. 2021-09-15 13:02:15 +09:00
Yukihiro "Matz" Matsumoto 20635e6bdc debug.c: export integer compressing functions.
- mrb_packed_int_len()
- mrb_packed_int_encode()
- mrb_packed_int_decode()
2021-08-18 17:18:04 +09:00
Yukihiro "Matz" Matsumoto 504d05232d mrdb.c: do not skip OP_JMP on step execution. 2021-08-02 16:19:08 +09:00
Yukihiro "Matz" Matsumoto 5c804cf68f Remove redundant include headers.
- stdlib.h
- stddef.h
- stdint.h
- stdarg.h
- limits.h
- float.h
2021-07-25 13:07:10 +09:00
dearblue c8750048be Avoid implicit casting from void pointers for C++ 2021-07-17 20:21:30 +09:00
Yukihiro "Matz" Matsumoto b5039fdb6c debug.h: use uint8_t instead of char for BER compressed binary. 2021-07-09 14:10:48 +09:00
Yukihiro "Matz" Matsumoto 06b1662807 mruby-bin-debugger: remove unused local variables. 2021-07-08 09:58:44 +09:00
Yukihiro "Matz" Matsumoto c572165292 mruby-bin-debugger: support mrb_debug_line_packed_map. 2021-07-08 09:54:11 +09:00
Yukihiro "Matz" Matsumoto fb1d4ff682 mruby-bin-debugger: rename prefix 'mrb_debug_' to mrdb_. 2021-07-08 07:24:12 +09:00
Yukihiro "Matz" Matsumoto 7c362ee723 Merge branch 'mrb_debug_strdup-and-strndup' of https://github.com/cremno/mruby into cremno-mrb_debug_strdup-and-strndup 2021-07-06 17:01:37 +09:00
KOBAYASHI Shuji 00a13e22dd Use global defines for mruby-bin-debugger 2021-03-22 12:02:26 +09:00
John Bampton 1c9b1bfeb7 feat: add pre-commit framework 2021-03-01 10:06:17 +10:00
Yukihiro "Matz" Matsumoto 8684abd697 Remove periods from error messages according to the convention. 2021-02-28 19:32:52 +09:00
John Bampton be40e9c783 chore: fix spelling
Normally a single spell checker can't find all the mistakes or check all types of code.

These mistakes were found by another spell checker inside my editor with a more manual sift / find.
2021-02-13 17:21:17 +10:00