summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2021-08-18 08:06:20 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2021-08-18 17:18:04 +0900
commit20635e6bdc2899d649c2f3fe12f4e82739ee2a54 (patch)
treecb280996f1b7f9c117290239f444b28f594795a9
parent96a8703ca8edf78b685808feb33730c587172e4d (diff)
downloadmruby-20635e6bdc2899d649c2f3fe12f4e82739ee2a54.tar.gz
mruby-20635e6bdc2899d649c2f3fe12f4e82739ee2a54.zip
debug.c: export integer compressing functions.
- mrb_packed_int_len() - mrb_packed_int_encode() - mrb_packed_int_decode()
-rw-r--r--mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c19
-rw-r--r--src/debug.c24
2 files changed, 15 insertions, 28 deletions
diff --git a/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c b/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c
index a26630599..66cc9ad94 100644
--- a/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c
+++ b/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c
@@ -20,20 +20,7 @@
#define MRB_DEBUG_BP_FILE_OK (0x0001)
#define MRB_DEBUG_BP_LINENO_OK (0x0002)
-static uint32_t
-packed_int_decode(uint8_t *p, uint8_t **newpos)
-{
- size_t i = 0, shift = 0;
- uint32_t n = 0;
-
- do {
- n |= ((uint32_t)(p[i] & 0x7f)) << shift;
- i++;
- shift += 7;
- } while (shift < sizeof(uint32_t) * 8 && (p[i - 1] & 0x80));
- if (newpos) *newpos = p + i;
- return n;
-}
+uint32_t mrb_packed_int_decode(uint8_t *p, uint8_t **newpos);
static uint16_t
check_lineno(mrb_irep_debug_info_file *info_file, uint16_t lineno)
@@ -64,8 +51,8 @@ check_lineno(mrb_irep_debug_info_file *info_file, uint16_t lineno)
uint8_t *pend = p + count;
uint32_t line = 0;
while (p < pend) {
- packed_int_decode(p, &p);
- line += packed_int_decode(p, &p);
+ mrb_packed_int_decode(p, &p);
+ line += mrb_packed_int_decode(p, &p);
if (line == lineno) return lineno;
}
}
diff --git a/src/debug.c b/src/debug.c
index c7162daee..e570e8068 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -35,8 +35,8 @@ get_file(mrb_irep_debug_info *info, uint32_t pc)
return *ret;
}
-static size_t
-packed_int_len(uint32_t num)
+size_t
+mrb_packed_int_len(uint32_t num)
{
size_t llen = 0;
@@ -46,8 +46,8 @@ packed_int_len(uint32_t num)
return llen;
}
-static size_t
-packed_int_encode(uint32_t num, uint8_t *p, uint8_t *pend)
+size_t
+mrb_packed_int_encode(uint32_t num, uint8_t *p, uint8_t *pend)
{
size_t llen = 0;
@@ -62,8 +62,8 @@ packed_int_encode(uint32_t num, uint8_t *p, uint8_t *pend)
return llen;
}
-static uint32_t
-packed_int_decode(uint8_t *p, uint8_t **newpos)
+uint32_t
+mrb_packed_int_decode(uint8_t *p, uint8_t **newpos)
{
size_t i = 0, shift = 0;
uint32_t n = 0;
@@ -135,8 +135,8 @@ mrb_debug_get_line(mrb_state *mrb, const mrb_irep *irep, uint32_t pc)
uint8_t *pend = p + f->line_entry_count;
uint32_t pos = 0, line = 0, line_diff;
while (p < pend) {
- pos += packed_int_decode(p, &p);
- line_diff = packed_int_decode(p, &p);
+ pos += mrb_packed_int_decode(p, &p);
+ line_diff = mrb_packed_int_decode(p, &p);
if (pc < pos) break;
line += line_diff;
}
@@ -204,9 +204,9 @@ mrb_debug_info_append_file(mrb_state *mrb, mrb_irep_debug_info *d,
for (i = 0; i < file_pc_count; ++i) {
if (lines[start_pos + i] == prev_line) continue;
- packed_size += packed_int_len(start_pos+i-prev_pc);
+ packed_size += mrb_packed_int_len(start_pos+i-prev_pc);
prev_pc = start_pos+i;
- packed_size += packed_int_len(lines[start_pos+i]-prev_line);
+ packed_size += mrb_packed_int_len(lines[start_pos+i]-prev_line);
prev_line = lines[start_pos + i];
}
p = f->lines.packed_map = (uint8_t*)mrb_malloc(mrb, packed_size);
@@ -214,9 +214,9 @@ mrb_debug_info_append_file(mrb_state *mrb, mrb_irep_debug_info *d,
prev_line = 0; prev_pc = 0;
for (i = 0; i < file_pc_count; ++i) {
if (lines[start_pos + i] == prev_line) continue;
- p += packed_int_encode(start_pos+i-prev_pc, p, pend);
+ p += mrb_packed_int_encode(start_pos+i-prev_pc, p, pend);
prev_pc = start_pos + i;
- p += packed_int_encode(lines[start_pos + i]-prev_line, p, pend);
+ p += mrb_packed_int_encode(lines[start_pos + i]-prev_line, p, pend);
prev_line = lines[start_pos + i];
}
f->line_entry_count = (uint32_t)packed_size;