Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
385e5d6e
Commit
385e5d6e
authored
Sep 04, 2013
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
resolve conflict
parents
cc64e6e2
b8d5f0f6
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
158 additions
and
117 deletions
+158
-117
include/mruby/debug.h
include/mruby/debug.h
+17
-17
src/debug.c
src/debug.c
+46
-38
src/dump.c
src/dump.c
+51
-34
src/load.c
src/load.c
+35
-21
src/parse.y
src/parse.y
+8
-5
src/state.c
src/state.c
+1
-2
No files found.
include/mruby/debug.h
View file @
385e5d6e
/*
** mruby/debug.h - mruby debug info
**
** See Copyright Notice in mruby.h
*/
#ifndef MRUBY_DEBUG_H
#ifndef MRUBY_DEBUG_H
#define MRUBY_DEBUG_H
#define MRUBY_DEBUG_H
...
@@ -5,9 +11,6 @@
...
@@ -5,9 +11,6 @@
extern
"C"
{
extern
"C"
{
#endif
#endif
#include <stdint.h>
#include "mruby/value.h"
typedef
enum
mrb_debug_line_type
{
typedef
enum
mrb_debug_line_type
{
mrb_debug_line_ary
=
0
,
mrb_debug_line_ary
=
0
,
mrb_debug_line_flat_map
=
1
mrb_debug_line_flat_map
=
1
...
@@ -20,43 +23,40 @@ typedef struct mrb_irep_debug_info_line {
...
@@ -20,43 +23,40 @@ typedef struct mrb_irep_debug_info_line {
typedef
struct
mrb_irep_debug_info_file
{
typedef
struct
mrb_irep_debug_info_file
{
uint32_t
start_pos
;
uint32_t
start_pos
;
c
har
const
*
filename
;
c
onst
char
*
filename
;
mrb_sym
filename_sym
;
mrb_sym
filename_sym
;
uint32_t
line_entry_count
;
uint32_t
line_entry_count
;
mrb_debug_line_type
line_type
;
mrb_debug_line_type
line_type
;
union
{
union
{
void
*
line_ptr
;
void
*
line_ptr
;
mrb_irep_debug_info_line
*
line_flat_map
;
mrb_irep_debug_info_line
*
line_flat_map
;
uint16_t
*
line_ary
;
uint16_t
*
line_ary
;
};
};
}
mrb_irep_debug_info_file
;
}
mrb_irep_debug_info_file
;
typedef
struct
mrb_irep_debug_info
{
typedef
struct
mrb_irep_debug_info
{
uint32_t
pc_count
;
uint32_t
pc_count
;
uint16_t
flen
;
uint16_t
flen
;
mrb_irep_debug_info_file
**
files
;
mrb_irep_debug_info_file
**
files
;
}
mrb_irep_debug_info
;
}
mrb_irep_debug_info
;
struct
mrb_irep
;
struct
mrb_state
;
/*
/*
* get line from irep's debug info and program counter
* get line from irep's debug info and program counter
* @return returns NULL if not found
* @return returns NULL if not found
*/
*/
c
har
const
*
mrb_debug_get_filename
(
struct
mrb_irep
*
irep
,
uint32_t
pc
);
c
onst
char
*
mrb_debug_get_filename
(
mrb_irep
*
irep
,
uint32_t
pc
);
/*
/*
* get line from irep's debug info and program counter
* get line from irep's debug info and program counter
* @return returns -1 if not found
* @return returns -1 if not found
*/
*/
int32_t
mrb_debug_get_line
(
struct
mrb_irep
*
irep
,
uint32_t
pc
);
int32_t
mrb_debug_get_line
(
mrb_irep
*
irep
,
uint32_t
pc
);
mrb_irep_debug_info_file
*
mrb_debug_info_append_file
(
mrb_irep_debug_info_file
*
mrb_debug_info_append_file
(
struct
mrb_state
*
mrb
,
struct
mrb_irep
*
irep
,
mrb_state
*
mrb
,
mrb_irep
*
irep
,
uint32_t
start_pos
,
uint32_t
end_pos
);
uint32_t
start_pos
,
uint32_t
end_pos
);
mrb_irep_debug_info
*
mrb_debug_info_alloc
(
struct
mrb_state
*
mrb
,
struct
mrb_irep
*
irep
);
mrb_irep_debug_info
*
mrb_debug_info_alloc
(
mrb_state
*
mrb
,
mrb_irep
*
irep
);
void
mrb_debug_info_free
(
struct
mrb_state
*
mrb
,
mrb_irep_debug_info
*
d
);
void
mrb_debug_info_free
(
mrb_state
*
mrb
,
mrb_irep_debug_info
*
d
);
#if defined(__cplusplus)
#if defined(__cplusplus)
}
/* extern "C" { */
}
/* extern "C" { */
...
...
src/debug.c
View file @
385e5d6e
#include "mruby/debug.h"
#include <string.h>
#include "mruby.h"
#include "mruby.h"
#include "mruby/irep.h"
#include "mruby/irep.h"
#include "mruby/debug.h"
#include <string.h>
static
mrb_irep_debug_info_file
*
get_file
(
mrb_irep_debug_info
*
info
,
uint32_t
pc
)
static
mrb_irep_debug_info_file
*
get_file
(
mrb_irep_debug_info
*
info
,
uint32_t
const
pc
)
{
{
if
(
pc
>=
info
->
pc_count
)
{
return
NULL
;
}
mrb_irep_debug_info_file
**
ret
;
int32_t
count
;
if
(
pc
>=
info
->
pc_count
)
{
return
NULL
;
}
// get upper bound
// get upper bound
mrb_irep_debug_info_file
**
ret
=
info
->
files
;
ret
=
info
->
files
;
int32_t
count
=
info
->
flen
;
count
=
info
->
flen
;
while
(
count
>
0
)
{
while
(
count
>
0
)
{
int32_t
const
step
=
count
/
2
;
int32_t
step
=
count
/
2
;
mrb_irep_debug_info_file
**
const
it
=
ret
+
step
;
mrb_irep_debug_info_file
**
it
=
ret
+
step
;
if
(
!
(
pc
<
(
*
it
)
->
start_pos
))
{
if
(
!
(
pc
<
(
*
it
)
->
start_pos
))
{
ret
=
it
+
1
;
ret
=
it
+
1
;
count
-=
step
+
1
;
count
-=
step
+
1
;
...
@@ -35,7 +35,7 @@ get_file(mrb_irep_debug_info* info, uint32_t const pc)
...
@@ -35,7 +35,7 @@ get_file(mrb_irep_debug_info* info, uint32_t const pc)
}
}
static
mrb_debug_line_type
static
mrb_debug_line_type
select_line_type
(
uint16_t
const
*
lines
,
size_t
lines_len
)
select_line_type
(
const
uint16_t
*
lines
,
size_t
lines_len
)
{
{
size_t
line_count
=
0
;
size_t
line_count
=
0
;
int
prev_line
=
-
1
;
int
prev_line
=
-
1
;
...
@@ -50,7 +50,7 @@ select_line_type(uint16_t const* lines, size_t lines_len)
...
@@ -50,7 +50,7 @@ select_line_type(uint16_t const* lines, size_t lines_len)
}
}
char
const
*
char
const
*
mrb_debug_get_filename
(
mrb_irep
*
irep
,
uint32_t
pc
)
mrb_debug_get_filename
(
mrb_irep
*
irep
,
uint32_t
pc
)
{
{
if
(
irep
&&
pc
<
irep
->
ilen
)
{
if
(
irep
&&
pc
<
irep
->
ilen
)
{
mrb_irep_debug_info_file
*
f
=
NULL
;
mrb_irep_debug_info_file
*
f
=
NULL
;
...
@@ -63,7 +63,7 @@ mrb_debug_get_filename(mrb_irep* irep, uint32_t pc)
...
@@ -63,7 +63,7 @@ mrb_debug_get_filename(mrb_irep* irep, uint32_t pc)
}
}
int32_t
int32_t
mrb_debug_get_line
(
mrb_irep
*
irep
,
uint32_t
cons
t
pc
)
mrb_debug_get_line
(
mrb_irep
*
irep
,
uint32_
t
pc
)
{
{
if
(
irep
&&
pc
<
irep
->
ilen
)
{
if
(
irep
&&
pc
<
irep
->
ilen
)
{
mrb_irep_debug_info_file
*
f
=
NULL
;
mrb_irep_debug_info_file
*
f
=
NULL
;
...
@@ -78,11 +78,11 @@ mrb_debug_get_line(mrb_irep* irep, uint32_t const pc)
...
@@ -78,11 +78,11 @@ mrb_debug_get_line(mrb_irep* irep, uint32_t const pc)
case
mrb_debug_line_flat_map
:
{
case
mrb_debug_line_flat_map
:
{
// get upper bound
// get upper bound
mrb_irep_debug_info_line
*
ret
=
f
->
line_flat_map
;
mrb_irep_debug_info_line
*
ret
=
f
->
line_flat_map
;
int32_t
count
=
f
->
line_entry_count
;
u
int32_t
count
=
f
->
line_entry_count
;
while
(
count
>
0
)
{
while
(
count
>
0
)
{
int32_t
const
step
=
count
/
2
;
int32_t
step
=
count
/
2
;
mrb_irep_debug_info_line
*
const
it
=
ret
+
step
;
mrb_irep_debug_info_line
*
it
=
ret
+
step
;
if
(
!
(
pc
<
it
->
start_pos
))
{
if
(
!
(
pc
<
it
->
start_pos
))
{
ret
=
it
+
1
;
ret
=
it
+
1
;
count
-=
step
+
1
;
count
-=
step
+
1
;
...
@@ -106,49 +106,56 @@ mrb_debug_get_line(mrb_irep* irep, uint32_t const pc)
...
@@ -106,49 +106,56 @@ mrb_debug_get_line(mrb_irep* irep, uint32_t const pc)
return
-
1
;
return
-
1
;
}
}
mrb_irep_debug_info
*
mrb_irep_debug_info
*
mrb_debug_info_alloc
(
mrb_state
*
mrb
,
mrb_irep
*
irep
)
mrb_debug_info_alloc
(
mrb_state
*
mrb
,
mrb_irep
*
irep
)
{
{
static
mrb_irep_debug_info
const
initial
=
{
0
,
0
,
NULL
};
static
const
mrb_irep_debug_info
initial
=
{
0
,
0
,
NULL
};
mrb_
assert
(
!
irep
->
debug_info
)
;
mrb_
irep_debug_info
*
ret
;
mrb_irep_debug_info
*
const
ret
=
(
mrb_irep_debug_info
*
)
mrb_malloc
(
mrb
,
sizeof
(
mrb_irep_debug_info
));
mrb_assert
(
!
irep
->
debug_info
);
ret
=
(
mrb_irep_debug_info
*
)
mrb_malloc
(
mrb
,
sizeof
(
*
ret
));
*
ret
=
initial
;
*
ret
=
initial
;
irep
->
debug_info
=
ret
;
irep
->
debug_info
=
ret
;
return
ret
;
return
ret
;
}
}
mrb_irep_debug_info_file
*
mrb_irep_debug_info_file
*
mrb_debug_info_append_file
(
mrb_state
*
mrb
,
mrb_irep
*
irep
,
mrb_debug_info_append_file
(
mrb_state
*
mrb
,
mrb_irep
*
irep
,
uint32_t
const
start_pos
,
uint32_t
cons
t
end_pos
)
uint32_t
start_pos
,
uint32_
t
end_pos
)
{
{
mrb_irep_debug_info
*
info
;
mrb_irep_debug_info_file
*
ret
;
uint32_t
file_pc_count
;
size_t
fn_len
;
size_t
len
;
uint32_t
i
;
if
(
!
irep
->
debug_info
)
{
return
NULL
;
}
if
(
!
irep
->
debug_info
)
{
return
NULL
;
}
mrb_assert
(
irep
->
filename
);
mrb_assert
(
irep
->
filename
);
mrb_assert
(
irep
->
lines
);
mrb_assert
(
irep
->
lines
);
mrb_irep_debug_info
*
info
=
irep
->
debug_info
;
info
=
irep
->
debug_info
;
if
(
info
->
flen
>
0
&&
strcmp
(
irep
->
filename
,
info
->
files
[
info
->
flen
-
1
]
->
filename
)
==
0
)
{
if
(
info
->
flen
>
0
&&
strcmp
(
irep
->
filename
,
info
->
files
[
info
->
flen
-
1
]
->
filename
)
==
0
)
{
return
NULL
;
return
NULL
;
}
}
mrb_irep_debug_info_file
*
const
ret
=
ret
=
(
mrb_irep_debug_info_file
*
)
mrb_malloc
(
mrb
,
sizeof
(
*
ret
));
(
mrb_irep_debug_info_file
*
)
mrb_malloc
(
mrb
,
sizeof
(
mrb_irep_debug_info_file
));
info
->
files
=
info
->
files
=
(
mrb_irep_debug_info_file
*
)
info
->
files
(
mrb_irep_debug_info_file
*
)
info
->
files
?
mrb_realloc
(
mrb
,
info
->
files
,
sizeof
(
mrb_irep_debug_info_file
*
)
*
(
info
->
flen
+
1
))
?
mrb_realloc
(
mrb
,
info
->
files
,
sizeof
(
mrb_irep_debug_info_file
*
)
*
(
info
->
flen
+
1
))
:
mrb_malloc
(
mrb
,
sizeof
(
mrb_irep_debug_info_file
*
));
:
mrb_malloc
(
mrb
,
sizeof
(
mrb_irep_debug_info_file
*
));
info
->
files
[
info
->
flen
++
]
=
ret
;
info
->
files
[
info
->
flen
++
]
=
ret
;
uint32_t
const
file_pc_count
=
end_pos
-
start_pos
;
file_pc_count
=
end_pos
-
start_pos
;
ret
->
start_pos
=
start_pos
;
ret
->
start_pos
=
start_pos
;
info
->
pc_count
=
end_pos
;
info
->
pc_count
=
end_pos
;
size_t
const
fn_len
=
strlen
(
irep
->
filename
);
fn_len
=
strlen
(
irep
->
filename
);
ret
->
filename_sym
=
mrb_intern2
(
mrb
,
irep
->
filename
,
fn_len
);
ret
->
filename_sym
=
mrb_intern2
(
mrb
,
irep
->
filename
,
fn_len
);
size_t
len
=
0
;
len
=
0
;
ret
->
filename
=
mrb_sym2name_len
(
mrb
,
ret
->
filename_sym
,
&
len
);
ret
->
filename
=
mrb_sym2name_len
(
mrb
,
ret
->
filename_sym
,
&
len
);
ret
->
line_type
=
select_line_type
(
irep
->
lines
+
start_pos
,
end_pos
-
start_pos
);
ret
->
line_type
=
select_line_type
(
irep
->
lines
+
start_pos
,
end_pos
-
start_pos
);
...
@@ -158,24 +165,24 @@ mrb_debug_info_append_file(mrb_state* mrb, mrb_irep* irep,
...
@@ -158,24 +165,24 @@ mrb_debug_info_append_file(mrb_state* mrb, mrb_irep* irep,
case
mrb_debug_line_ary
:
case
mrb_debug_line_ary
:
ret
->
line_entry_count
=
file_pc_count
;
ret
->
line_entry_count
=
file_pc_count
;
ret
->
line_ary
=
mrb_malloc
(
mrb
,
sizeof
(
uint16_t
)
*
file_pc_count
);
ret
->
line_ary
=
mrb_malloc
(
mrb
,
sizeof
(
uint16_t
)
*
file_pc_count
);
uint32_t
i
;
for
(
i
=
0
;
i
<
file_pc_count
;
++
i
)
{
for
(
i
=
0
;
i
<
file_pc_count
;
++
i
)
{
ret
->
line_ary
[
i
]
=
irep
->
lines
[
start_pos
+
i
];
ret
->
line_ary
[
i
]
=
irep
->
lines
[
start_pos
+
i
];
}
}
break
;
break
;
case
mrb_debug_line_flat_map
:
{
case
mrb_debug_line_flat_map
:
{
uint16_t
prev_line
=
0
;
mrb_irep_debug_info_line
m
;
ret
->
line_flat_map
=
mrb_malloc
(
mrb
,
sizeof
(
mrb_irep_debug_info_line
)
*
1
);
ret
->
line_flat_map
=
mrb_malloc
(
mrb
,
sizeof
(
mrb_irep_debug_info_line
)
*
1
);
ret
->
line_entry_count
=
0
;
ret
->
line_entry_count
=
0
;
uint16_t
prev_line
=
0
;
uint32_t
i
;
for
(
i
=
0
;
i
<
file_pc_count
;
++
i
)
{
for
(
i
=
0
;
i
<
file_pc_count
;
++
i
)
{
if
(
irep
->
lines
[
start_pos
+
i
]
==
prev_line
)
{
continue
;
}
if
(
irep
->
lines
[
start_pos
+
i
]
==
prev_line
)
{
continue
;
}
ret
->
line_flat_map
=
mrb_realloc
(
ret
->
line_flat_map
=
mrb_realloc
(
mrb
,
ret
->
line_flat_map
,
mrb
,
ret
->
line_flat_map
,
sizeof
(
mrb_irep_debug_info_line
)
*
(
ret
->
line_entry_count
+
1
));
sizeof
(
mrb_irep_debug_info_line
)
*
(
ret
->
line_entry_count
+
1
));
mrb_irep_debug_info_line
const
m
=
{
start_pos
+
i
,
irep
->
lines
[
start_pos
+
i
]
};
m
.
start_pos
=
start_pos
+
i
;
m
.
line
=
irep
->
lines
[
start_pos
+
i
];
ret
->
line_flat_map
[
ret
->
line_entry_count
]
=
m
;
ret
->
line_flat_map
[
ret
->
line_entry_count
]
=
m
;
// update
// update
...
@@ -191,11 +198,12 @@ mrb_debug_info_append_file(mrb_state* mrb, mrb_irep* irep,
...
@@ -191,11 +198,12 @@ mrb_debug_info_append_file(mrb_state* mrb, mrb_irep* irep,
}
}
void
void
mrb_debug_info_free
(
mrb_state
*
mrb
,
mrb_irep_debug_info
*
d
)
mrb_debug_info_free
(
mrb_state
*
mrb
,
mrb_irep_debug_info
*
d
)
{
{
uint32_t
i
;
if
(
!
d
)
{
return
;
}
if
(
!
d
)
{
return
;
}
uint32_t
i
;
for
(
i
=
0
;
i
<
d
->
flen
;
++
i
)
{
for
(
i
=
0
;
i
<
d
->
flen
;
++
i
)
{
mrb_assert
(
d
->
files
[
i
]);
mrb_assert
(
d
->
files
[
i
]);
mrb_free
(
mrb
,
d
->
files
[
i
]
->
line_ptr
);
mrb_free
(
mrb
,
d
->
files
[
i
]
->
line_ptr
);
...
...
src/dump.c
View file @
385e5d6e
...
@@ -390,14 +390,14 @@ mrb_write_section_lineno(mrb_state *mrb, size_t start_index, uint8_t *bin)
...
@@ -390,14 +390,14 @@ mrb_write_section_lineno(mrb_state *mrb, size_t start_index, uint8_t *bin)
}
}
static
size_t
static
size_t
get_debug_record_size
(
mrb_state
*
mrb
,
mrb_irep
*
irep
)
{
get_debug_record_size
(
mrb_state
*
mrb
,
mrb_irep
*
irep
)
(
void
)
mrb
;
{
size_t
ret
=
0
;
size_t
ret
=
0
;
uint32_t
f_idx
;
ret
+=
sizeof
(
uint32_t
);
// record size
ret
+=
sizeof
(
uint32_t
);
// record size
ret
+=
sizeof
(
uint16_t
);
// file count
ret
+=
sizeof
(
uint16_t
);
// file count
uint32_t
f_idx
;
for
(
f_idx
=
0
;
f_idx
<
irep
->
debug_info
->
flen
;
++
f_idx
)
{
for
(
f_idx
=
0
;
f_idx
<
irep
->
debug_info
->
flen
;
++
f_idx
)
{
mrb_irep_debug_info_file
const
*
file
=
irep
->
debug_info
->
files
[
f_idx
];
mrb_irep_debug_info_file
const
*
file
=
irep
->
debug_info
->
files
[
f_idx
];
...
@@ -424,8 +424,10 @@ get_debug_record_size(mrb_state* mrb, mrb_irep *irep) {
...
@@ -424,8 +424,10 @@ get_debug_record_size(mrb_state* mrb, mrb_irep *irep) {
}
}
static
int
static
int
find_filename_index
(
mrb_sym
const
*
ary
,
size_t
ary_len
,
mrb_sym
s
)
{
find_filename_index
(
const
mrb_sym
*
ary
,
size_t
ary_len
,
mrb_sym
s
)
mrb_int
i
;
{
size_t
i
;
for
(
i
=
0
;
i
<
ary_len
;
++
i
)
{
for
(
i
=
0
;
i
<
ary_len
;
++
i
)
{
if
(
ary
[
i
]
==
s
)
{
return
i
;
}
if
(
ary
[
i
]
==
s
)
{
return
i
;
}
}
}
...
@@ -433,20 +435,24 @@ find_filename_index(mrb_sym const* ary, size_t ary_len, mrb_sym s) {
...
@@ -433,20 +435,24 @@ find_filename_index(mrb_sym const* ary, size_t ary_len, mrb_sym s) {
}
}
static
int
static
int
write_debug_record
(
mrb_state
*
mrb
,
mrb_irep
*
irep
,
uint8_t
*
const
bin
,
mrb_sym
const
*
filenames
,
size_t
filenames_len
)
write_debug_record
(
mrb_state
*
mrb
,
mrb_irep
*
irep
,
uint8_t
*
bin
,
mrb_sym
const
*
filenames
,
size_t
filenames_len
)
{
{
uint8_t
*
cur
=
bin
+
sizeof
(
uint32_t
);
// skip record size
uint8_t
*
cur
;
uint32_t
f_idx
;
size_t
ret
;
cur
=
bin
+
sizeof
(
uint32_t
);
// skip record size
cur
+=
uint16_to_bin
(
irep
->
debug_info
->
flen
,
cur
);
// file count
cur
+=
uint16_to_bin
(
irep
->
debug_info
->
flen
,
cur
);
// file count
uint32_t
f_idx
;
for
(
f_idx
=
0
;
f_idx
<
irep
->
debug_info
->
flen
;
++
f_idx
)
{
for
(
f_idx
=
0
;
f_idx
<
irep
->
debug_info
->
flen
;
++
f_idx
)
{
mrb_irep_debug_info_file
const
*
file
=
irep
->
debug_info
->
files
[
f_idx
];
int
filename_idx
;
const
mrb_irep_debug_info_file
*
file
=
irep
->
debug_info
->
files
[
f_idx
];
// position
// position
cur
+=
uint32_to_bin
(
file
->
start_pos
,
cur
);
cur
+=
uint32_to_bin
(
file
->
start_pos
,
cur
);
// filename index
// filename index
int
const
filename_idx
=
find_filename_index
(
filenames
,
filenames_len
,
filename_idx
=
find_filename_index
(
filenames
,
filenames_len
,
file
->
filename_sym
);
file
->
filename_sym
);
mrb_assert
(
filename_idx
!=
-
1
);
mrb_assert
(
filename_idx
!=
-
1
);
cur
+=
uint16_to_bin
(
filename_idx
,
cur
);
cur
+=
uint16_to_bin
(
filename_idx
,
cur
);
...
@@ -474,7 +480,7 @@ write_debug_record(mrb_state* mrb, mrb_irep *irep, uint8_t * const bin, mrb_sym
...
@@ -474,7 +480,7 @@ write_debug_record(mrb_state* mrb, mrb_irep *irep, uint8_t * const bin, mrb_sym
}
}
}
}
size_t
const
ret
=
cur
-
bin
;
ret
=
cur
-
bin
;
uint32_to_bin
(
ret
,
bin
);
uint32_to_bin
(
ret
,
bin
);
mrb_assert
((
cur
-
bin
)
==
(
int
)
get_debug_record_size
(
mrb
,
irep
));
mrb_assert
((
cur
-
bin
)
==
(
int
)
get_debug_record_size
(
mrb
,
irep
));
...
@@ -483,32 +489,38 @@ write_debug_record(mrb_state* mrb, mrb_irep *irep, uint8_t * const bin, mrb_sym
...
@@ -483,32 +489,38 @@ write_debug_record(mrb_state* mrb, mrb_irep *irep, uint8_t * const bin, mrb_sym
}
}
static
int
static
int
mrb_write_section_debug
(
mrb_state
*
mrb
,
size_t
start_index
,
uint8_t
*
cur
)
mrb_write_section_debug
(
mrb_state
*
mrb
,
size_t
start_index
,
uint8_t
*
cur
)
{
{
uint32_t
section_size
=
0
;
uint32_t
section_size
=
0
;
uint8_t
*
const
bin
=
cur
;
const
uint8_t
*
bin
=
cur
;
struct
rite_section_debug_header
*
header
;
mrb_sym
*
filenames
;
size_t
filenames_len
;
uint8_t
*
filenames_len_out
;
size_t
irep_i
;
size_t
file_i
;
uint16_t
fn_len
;
size_t
i
;
if
(
mrb
==
NULL
||
start_index
>=
mrb
->
irep_len
||
cur
==
NULL
)
{
if
(
mrb
==
NULL
||
start_index
>=
mrb
->
irep_len
||
cur
==
NULL
)
{
return
MRB_DUMP_INVALID_ARGUMENT
;
return
MRB_DUMP_INVALID_ARGUMENT
;
}
}
struct
rite_section_debug_header
*
header
=
(
struct
rite_section_debug_header
*
)
bin
;
header
=
(
struct
rite_section_debug_header
*
)
bin
;
cur
+=
sizeof
(
struct
rite_section_debug_header
);
cur
+=
sizeof
(
struct
rite_section_debug_header
);
section_size
+=
sizeof
(
struct
rite_section_debug_header
);
section_size
+=
sizeof
(
struct
rite_section_debug_header
);
// filename table
// filename table
mrb_sym
*
filenames
=
(
mrb_sym
*
)
mrb_malloc
(
mrb
,
sizeof
(
mrb_sym
*
)
*
1
);
filenames
=
(
mrb_sym
*
)
mrb_malloc
(
mrb
,
sizeof
(
mrb_sym
*
)
*
1
);
size_t
filenames_len
=
0
;
filenames_len
=
0
;
uint8_t
*
const
filenames_len_out
=
cur
;
filenames_len_out
=
cur
;
cur
+=
sizeof
(
uint16_t
);
cur
+=
sizeof
(
uint16_t
);
section_size
+=
sizeof
(
uint16_t
);
section_size
+=
sizeof
(
uint16_t
);
size_t
irep_i
;
for
(
irep_i
=
start_index
;
irep_i
<
mrb
->
irep_len
;
++
irep_i
)
{
for
(
irep_i
=
start_index
;
irep_i
<
mrb
->
irep_len
;
++
irep_i
)
{
mrb_irep_debug_info
const
*
debug_info
=
mrb
->
irep
[
irep_i
]
->
debug_info
;
mrb_irep_debug_info
*
debug_info
=
mrb
->
irep
[
irep_i
]
->
debug_info
;
size_t
file_i
;
for
(
file_i
=
0
;
file_i
<
debug_info
->
flen
;
++
file_i
)
{
for
(
file_i
=
0
;
file_i
<
debug_info
->
flen
;
++
file_i
)
{
mrb_irep_debug_info_file
const
*
file
=
debug_info
->
files
[
file_i
];
mrb_irep_debug_info_file
*
file
=
debug_info
->
files
[
file_i
];
if
(
find_filename_index
(
filenames
,
filenames_len
,
file
->
filename_sym
)
!=
-
1
)
continue
;
if
(
find_filename_index
(
filenames
,
filenames_len
,
file
->
filename_sym
)
!=
-
1
)
continue
;
// register filename
// register filename
...
@@ -516,7 +528,7 @@ mrb_write_section_debug(mrb_state* mrb, size_t start_index, uint8_t *cur)
...
@@ -516,7 +528,7 @@ mrb_write_section_debug(mrb_state* mrb, size_t start_index, uint8_t *cur)
filenames
[
filenames_len
-
1
]
=
file
->
filename_sym
;
filenames
[
filenames_len
-
1
]
=
file
->
filename_sym
;
// filename
// filename
uint16_t
const
fn_len
=
strlen
(
file
->
filename
);
fn_len
=
(
uint16_t
)
strlen
(
file
->
filename
);
cur
+=
uint16_to_bin
(
fn_len
,
cur
);
cur
+=
uint16_to_bin
(
fn_len
,
cur
);
memcpy
(
cur
,
file
->
filename
,
fn_len
);
memcpy
(
cur
,
file
->
filename
,
fn_len
);
cur
+=
fn_len
;
cur
+=
fn_len
;
...
@@ -527,7 +539,6 @@ mrb_write_section_debug(mrb_state* mrb, size_t start_index, uint8_t *cur)
...
@@ -527,7 +539,6 @@ mrb_write_section_debug(mrb_state* mrb, size_t start_index, uint8_t *cur)
uint16_to_bin
(
filenames_len
,
filenames_len_out
);
uint16_to_bin
(
filenames_len
,
filenames_len_out
);
// records
// records
size_t
i
;
for
(
i
=
start_index
;
i
<
mrb
->
irep_len
;
++
i
)
{
for
(
i
=
start_index
;
i
<
mrb
->
irep_len
;
++
i
)
{
uint32_t
rlen
=
write_debug_record
(
mrb
,
mrb
->
irep
[
i
],
cur
,
filenames
,
filenames_len
);
uint32_t
rlen
=
write_debug_record
(
mrb
,
mrb
->
irep
[
i
],
cur
,
filenames
,
filenames_len
);
cur
+=
rlen
;
cur
+=
rlen
;
...
@@ -545,9 +556,9 @@ mrb_write_section_debug(mrb_state* mrb, size_t start_index, uint8_t *cur)
...
@@ -545,9 +556,9 @@ mrb_write_section_debug(mrb_state* mrb, size_t start_index, uint8_t *cur)
}
}
static
int
static
int
write_rite_binary_header
(
mrb_state
*
mrb
,
size_t
binary_size
,
uint8_t
*
bin
)
write_rite_binary_header
(
mrb_state
*
mrb
,
size_t
binary_size
,
uint8_t
*
bin
)
{
{
struct
rite_binary_header
*
header
=
(
struct
rite_binary_header
*
)
bin
;
struct
rite_binary_header
*
header
=
(
struct
rite_binary_header
*
)
bin
;
uint16_t
crc
;
uint16_t
crc
;
size_t
offset
;
size_t
offset
;
...
@@ -564,7 +575,8 @@ write_rite_binary_header(mrb_state *mrb, size_t binary_size, uint8_t* bin)
...
@@ -564,7 +575,8 @@ write_rite_binary_header(mrb_state *mrb, size_t binary_size, uint8_t* bin)
return
MRB_DUMP_OK
;
return
MRB_DUMP_OK
;
}
}
mrb_bool
is_debug_info_defined
(
mrb_state
*
mrb
,
size_t
const
start_index
)
{
mrb_bool
is_debug_info_defined
(
mrb_state
*
mrb
,
size_t
const
start_index
)
{
size_t
i
;
size_t
i
;
for
(
i
=
start_index
;
i
<
mrb
->
irep_len
;
++
i
)
{
for
(
i
=
start_index
;
i
<
mrb
->
irep_len
;
++
i
)
{
if
(
!
mrb
->
irep
[
i
]
->
debug_info
)
{
return
0
;
}
if
(
!
mrb
->
irep
[
i
]
->
debug_info
)
{
return
0
;
}
...
@@ -598,28 +610,33 @@ mrb_dump_irep(mrb_state *mrb, size_t start_index, int debug_info, uint8_t **bin,
...
@@ -598,28 +610,33 @@ mrb_dump_irep(mrb_state *mrb, size_t start_index, int debug_info, uint8_t **bin,
/* DEBUG section size */
/* DEBUG section size */
if
(
debug_info
)
{
if
(
debug_info
)
{
if
(
debug_info_defined
)
{
if
(
debug_info_defined
)
{
mrb_sym
*
filenames
;
size_t
filenames_len
;
size_t
irep_i
;
size_t
file_i
;
section_lineno_size
+=
sizeof
(
struct
rite_section_debug_header
);
section_lineno_size
+=
sizeof
(
struct
rite_section_debug_header
);
// filename table
// filename table
mrb_sym
*
filenames
=
mrb_malloc
(
mrb
,
sizeof
(
mrb_sym
*
)
+
1
);
filenames
=
(
mrb_sym
*
)
mrb_malloc
(
mrb
,
sizeof
(
mrb_sym
*
)
+
1
);
size_t
filenames_len
=
0
;
filenames_len
=
0
;
// filename table size
// filename table size
section_lineno_size
+=
sizeof
(
uint16_t
);
section_lineno_size
+=
sizeof
(
uint16_t
);
size_t
irep_i
;
for
(
irep_i
=
start_index
;
irep_i
<
mrb
->
irep_len
;
++
irep_i
)
{
for
(
irep_i
=
start_index
;
irep_i
<
mrb
->
irep_len
;
++
irep_i
)
{
mrb_irep_debug_info
const
*
di
=
mrb
->
irep
[
irep_i
]
->
debug_info
;
mrb_irep_debug_info
*
di
=
mrb
->
irep
[
irep_i
]
->
debug_info
;
size_t
file_i
;
for
(
file_i
=
0
;
file_i
<
di
->
flen
;
++
file_i
)
{
for
(
file_i
=
0
;
file_i
<
di
->
flen
;
++
file_i
)
{
mrb_irep_debug_info_file
const
*
file
=
di
->
files
[
file_i
];
mrb_irep_debug_info_file
*
file
;
size_t
filename_len
;
file
=
di
->
files
[
file_i
];
if
(
find_filename_index
(
filenames
,
filenames_len
,
file
->
filename_sym
)
!=
-
1
)
continue
;
if
(
find_filename_index
(
filenames
,
filenames_len
,
file
->
filename_sym
)
!=
-
1
)
continue
;
// register filename
// register filename
filenames
=
(
mrb_sym
*
)
mrb_realloc
(
mrb
,
filenames
,
sizeof
(
mrb_sym
*
)
*
++
filenames_len
);
filenames
=
(
mrb_sym
*
)
mrb_realloc
(
mrb
,
filenames
,
sizeof
(
mrb_sym
*
)
*
++
filenames_len
);
filenames
[
filenames_len
-
1
]
=
file
->
filename_sym
;
filenames
[
filenames_len
-
1
]
=
file
->
filename_sym
;
// filename
// filename
size_t
filename_len
;
mrb_sym2name_len
(
mrb
,
file
->
filename_sym
,
&
filename_len
);
mrb_sym2name_len
(
mrb
,
file
->
filename_sym
,
&
filename_len
);
section_lineno_size
+=
sizeof
(
uint16_t
)
+
filename_len
;
section_lineno_size
+=
sizeof
(
uint16_t
)
+
filename_len
;
}
}
...
...
src/load.c
View file @
385e5d6e
...
@@ -300,51 +300,60 @@ error_exit:
...
@@ -300,51 +300,60 @@ error_exit:
return
result
;
return
result
;
}
}
static
int
read_rite_debug_record
(
mrb_state
*
mrb
,
uint8_t
const
*
start
,
size_t
irepno
,
uint32_t
*
len
,
mrb_sym
const
*
filenames
,
size_t
filenames_len
)
{
static
int
uint8_t
const
*
bin
=
start
;
read_rite_debug_record
(
mrb_state
*
mrb
,
const
uint8_t
*
start
,
size_t
irepno
,
uint32_t
*
len
,
const
mrb_sym
*
filenames
,
size_t
filenames_len
)
{
mrb_irep
*
const
irep
=
mrb
->
irep
[
irepno
];
const
uint8_t
*
bin
=
start
;
mrb_irep
*
irep
=
mrb
->
irep
[
irepno
];
size_t
record_size
;
uint16_t
f_idx
;
if
(
irep
->
debug_info
)
{
return
MRB_DUMP_INVALID_IREP
;
}
if
(
irep
->
debug_info
)
{
return
MRB_DUMP_INVALID_IREP
;
}
irep
->
debug_info
=
(
mrb_irep_debug_info
*
)
mrb_malloc
(
mrb
,
sizeof
(
mrb_irep_debug_info
));
irep
->
debug_info
=
(
mrb_irep_debug_info
*
)
mrb_malloc
(
mrb
,
sizeof
(
mrb_irep_debug_info
));
irep
->
debug_info
->
pc_count
=
irep
->
ilen
;
irep
->
debug_info
->
pc_count
=
irep
->
ilen
;
size_t
const
record_size
=
bin_to_uint32
(
bin
);
bin
+=
sizeof
(
uint32_t
);
record_size
=
bin_to_uint32
(
bin
);
bin
+=
sizeof
(
uint32_t
);
irep
->
debug_info
->
flen
=
bin_to_uint16
(
bin
);
irep
->
debug_info
->
flen
=
bin_to_uint16
(
bin
);
irep
->
debug_info
->
files
=
(
mrb_irep_debug_info_file
**
)
mrb_malloc
(
mrb
,
sizeof
(
mrb_irep_debug_info
*
)
*
irep
->
debug_info
->
flen
);
irep
->
debug_info
->
files
=
(
mrb_irep_debug_info_file
**
)
mrb_malloc
(
mrb
,
sizeof
(
mrb_irep_debug_info
*
)
*
irep
->
debug_info
->
flen
);
bin
+=
sizeof
(
uint16_t
);
bin
+=
sizeof
(
uint16_t
);
uint16_t
f_idx
;
for
(
f_idx
=
0
;
f_idx
<
irep
->
debug_info
->
flen
;
++
f_idx
)
{
for
(
f_idx
=
0
;
f_idx
<
irep
->
debug_info
->
flen
;
++
f_idx
)
{
mrb_irep_debug_info_file
*
const
file
=
(
mrb_irep_debug_info_file
*
)
mrb_malloc
(
mrb
,
sizeof
(
mrb_irep_debug_info_file
));
mrb_irep_debug_info_file
*
file
;
uint16_t
filename_idx
;
size_t
len
;
file
=
(
mrb_irep_debug_info_file
*
)
mrb_malloc
(
mrb
,
sizeof
(
*
file
));
irep
->
debug_info
->
files
[
f_idx
]
=
file
;
irep
->
debug_info
->
files
[
f_idx
]
=
file
;
file
->
start_pos
=
bin_to_uint32
(
bin
);
bin
+=
sizeof
(
uint32_t
);
file
->
start_pos
=
bin_to_uint32
(
bin
);
bin
+=
sizeof
(
uint32_t
);
// filename
// filename
uint16_t
const
filename_idx
=
bin_to_uint16
(
bin
);
filename_idx
=
bin_to_uint16
(
bin
);
bin
+=
sizeof
(
uint16_t
);
bin
+=
sizeof
(
uint16_t
);
mrb_assert
(
filename_idx
<
filenames_len
);
mrb_assert
(
filename_idx
<
filenames_len
);
file
->
filename_sym
=
filenames
[
filename_idx
];
file
->
filename_sym
=
filenames
[
filename_idx
];
size_t
len
=
0
;
len
=
0
;
file
->
filename
=
mrb_sym2name_len
(
mrb
,
file
->
filename_sym
,
&
len
);
file
->
filename
=
mrb_sym2name_len
(
mrb
,
file
->
filename_sym
,
&
len
);
file
->
line_entry_count
=
bin_to_uint32
(
bin
);
bin
+=
sizeof
(
uint32_t
);
file
->
line_entry_count
=
bin_to_uint32
(
bin
);
bin
+=
sizeof
(
uint32_t
);
file
->
line_type
=
bin_to_uint8
(
bin
);
bin
+=
sizeof
(
uint8_t
);
file
->
line_type
=
bin_to_uint8
(
bin
);
bin
+=
sizeof
(
uint8_t
);
switch
(
file
->
line_type
)
{
switch
(
file
->
line_type
)
{
case
mrb_debug_line_ary
:
{
case
mrb_debug_line_ary
:
{
file
->
line_ary
=
mrb_malloc
(
mrb
,
sizeof
(
uint16_t
)
*
file
->
line_entry_count
);
size_t
l
;
size_t
l
;
file
->
line_ary
=
(
uint16_t
*
)
mrb_malloc
(
mrb
,
sizeof
(
uint16_t
)
*
file
->
line_entry_count
);
for
(
l
=
0
;
l
<
file
->
line_entry_count
;
++
l
)
{
for
(
l
=
0
;
l
<
file
->
line_entry_count
;
++
l
)
{
file
->
line_ary
[
l
]
=
bin_to_uint16
(
bin
);
bin
+=
sizeof
(
uint16_t
);
file
->
line_ary
[
l
]
=
bin_to_uint16
(
bin
);
bin
+=
sizeof
(
uint16_t
);
}
}
}
break
;
}
break
;
case
mrb_debug_line_flat_map
:
{
case
mrb_debug_line_flat_map
:
{
file
->
line_flat_map
=
mrb_malloc
(
mrb
,
sizeof
(
mrb_irep_debug_info_line
)
*
file
->
line_entry_count
);
size_t
l
;
size_t
l
;
file
->
line_flat_map
=
mrb_malloc
(
mrb
,
sizeof
(
mrb_irep_debug_info_line
)
*
file
->
line_entry_count
);
for
(
l
=
0
;
l
<
file
->
line_entry_count
;
++
l
)
{
for
(
l
=
0
;
l
<
file
->
line_entry_count
;
++
l
)
{
file
->
line_flat_map
[
l
].
start_pos
=
bin_to_uint32
(
bin
);
bin
+=
sizeof
(
uint32_t
);
file
->
line_flat_map
[
l
].
start_pos
=
bin_to_uint32
(
bin
);
bin
+=
sizeof
(
uint32_t
);
file
->
line_flat_map
[
l
].
line
=
bin_to_uint16
(
bin
);
bin
+=
sizeof
(
uint16_t
);
file
->
line_flat_map
[
l
].
line
=
bin_to_uint16
(
bin
);
bin
+=
sizeof
(
uint16_t
);
...
@@ -365,24 +374,29 @@ static int read_rite_debug_record(mrb_state* mrb, uint8_t const *start, size_t i
...
@@ -365,24 +374,29 @@ static int read_rite_debug_record(mrb_state* mrb, uint8_t const *start, size_t i
}
}
static
int
static
int
read_rite_section_debug
(
mrb_state
*
mrb
,
const
uint8_t
*
start
,
size_t
sirep
)
read_rite_section_debug
(
mrb_state
*
mrb
,
const
uint8_t
*
start
,
size_t
sirep
)
{
{
uint8_t
const
*
bin
=
start
;
const
uint8_t
*
bin
;
struct
rite_section_debug_header
const
*
header
=
(
struct
rite_section_debug_header
const
*
)
bin
;
struct
rite_section_debug_header
*
header
;
bin
+=
sizeof
(
struct
rite_section_debug_header
);
uint16_t
i
;
uint16_t
i
;
int
result
;
int
result
;
uint16_t
nirep
;
size_t
filenames_len
;
mrb_sym
*
filenames
;
bin
=
start
;
header
=
(
struct
rite_section_debug_header
*
)
bin
;
bin
+=
sizeof
(
struct
rite_section_debug_header
);
uint16_t
const
nirep
=
bin_to_uint16
(
header
->
nirep
);
nirep
=
bin_to_uint16
(
header
->
nirep
);
size_t
const
filenames_len
=
bin_to_uint16
(
bin
);
filenames_len
=
bin_to_uint16
(
bin
);
bin
+=
sizeof
(
uint16_t
);
bin
+=
sizeof
(
uint16_t
);
mrb_sym
*
filenames
=
(
mrb_sym
*
)
mrb_malloc
(
mrb
,
sizeof
(
mrb_sym
*
)
*
filenames_len
);
filenames
=
(
mrb_sym
*
)
mrb_malloc
(
mrb
,
sizeof
(
mrb_sym
*
)
*
filenames_len
);
for
(
i
=
0
;
i
<
filenames_len
;
++
i
)
{
for
(
i
=
0
;
i
<
filenames_len
;
++
i
)
{
uint16_t
const
f_len
=
bin_to_uint16
(
bin
);
uint16_t
f_len
=
bin_to_uint16
(
bin
);
bin
+=
sizeof
(
uint16_t
);
bin
+=
sizeof
(
uint16_t
);
filenames
[
i
]
=
mrb_intern2
(
mrb
,
(
c
har
const
*
)
bin
,
f_len
);
filenames
[
i
]
=
mrb_intern2
(
mrb
,
(
c
onst
char
*
)
bin
,
f_len
);
bin
+=
f_len
;
bin
+=
f_len
;
}
}
...
...
src/parse.y
View file @
385e5d6e
...
@@ -5185,14 +5185,17 @@ mrbc_partial_hook(mrb_state *mrb, mrbc_context *c, int (*func)(struct mrb_parser
...
@@ -5185,14 +5185,17 @@ mrbc_partial_hook(mrb_state *mrb, mrbc_context *c, int (*func)(struct mrb_parser
}
}
void
void
mrb_parser_set_filename(struct mrb_parser_state
* p, char const*
f)
mrb_parser_set_filename(struct mrb_parser_state
*p, const char *
f)
{
{
mrb_sym
const sym = mrb_intern(p->mrb, f)
;
mrb_sym
sym
;
size_t len;
size_t len;
size_t i;
mrb_sym* new_table;
sym = mrb_intern_cstr(p->mrb, f);
p->filename = mrb_sym2name_len(p->mrb, sym, &len);
p->filename = mrb_sym2name_len(p->mrb, sym, &len);
p->lineno = (p->filename_table_length > 0)? 0 : 1;
p->lineno = (p->filename_table_length > 0)? 0 : 1;
size_t i;
for(i = 0; i < p->filename_table_length; ++i) {
for(i = 0; i < p->filename_table_length; ++i) {
if(p->filename_table[i] == sym) {
if(p->filename_table[i] == sym) {
p->current_filename_index = i;
p->current_filename_index = i;
...
@@ -5202,7 +5205,7 @@ mrb_parser_set_filename(struct mrb_parser_state* p, char const* f)
...
@@ -5202,7 +5205,7 @@ mrb_parser_set_filename(struct mrb_parser_state* p, char const* f)
p->current_filename_index = p->filename_table_length++;
p->current_filename_index = p->filename_table_length++;
mrb_sym* const
new_table = parser_palloc(p, sizeof(mrb_sym) * p->filename_table_length);
new_table = parser_palloc(p, sizeof(mrb_sym) * p->filename_table_length);
if (p->filename_table) {
if (p->filename_table) {
memcpy(new_table, p->filename_table, sizeof(mrb_sym) * p->filename_table_length);
memcpy(new_table, p->filename_table, sizeof(mrb_sym) * p->filename_table_length);
}
}
...
...
src/state.c
View file @
385e5d6e
...
@@ -115,9 +115,8 @@ mrb_irep_free(mrb_state *mrb, struct mrb_irep *irep)
...
@@ -115,9 +115,8 @@ mrb_irep_free(mrb_state *mrb, struct mrb_irep *irep)
mrb_free
(
mrb
,
irep
->
syms
);
mrb_free
(
mrb
,
irep
->
syms
);
mrb_free
(
mrb
,
(
void
*
)
irep
->
filename
);
mrb_free
(
mrb
,
(
void
*
)
irep
->
filename
);
mrb_free
(
mrb
,
irep
->
lines
);
mrb_free
(
mrb
,
irep
->
lines
);
mrb_free
(
mrb
,
irep
);
mrb_debug_info_free
(
mrb
,
irep
->
debug_info
);
mrb_debug_info_free
(
mrb
,
irep
->
debug_info
);
mrb_free
(
mrb
,
irep
);
}
}
void
void
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment