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
b8d5f0f6
Commit
b8d5f0f6
authored
Sep 04, 2013
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1497 from cremno/msvc-debug-info-feature
MSVC: compilation works again (+minor style fixes)
parents
179a0a70
501df718
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
158 additions
and
116 deletions
+158
-116
include/mruby/debug.h
include/mruby/debug.h
+17
-17
src/debug.c
src/debug.c
+47
-39
src/dump.c
src/dump.c
+51
-34
src/load.c
src/load.c
+35
-21
src/parse.y
src/parse.y
+8
-5
No files found.
include/mruby/debug.h
View file @
b8d5f0f6
/*
** mruby/debug.h - mruby debug info
**
** See Copyright Notice in mruby.h
*/
#ifndef MRUBY_DEBUG_H
#define MRUBY_DEBUG_H
...
...
@@ -5,9 +11,6 @@
extern
"C"
{
#endif
#include <stdint.h>
#include "mruby/value.h"
typedef
enum
mrb_debug_line_type
{
mrb_debug_line_ary
=
0
,
mrb_debug_line_flat_map
=
1
...
...
@@ -20,43 +23,40 @@ typedef struct mrb_irep_debug_info_line {
typedef
struct
mrb_irep_debug_info_file
{
uint32_t
start_pos
;
c
har
const
*
filename
;
c
onst
char
*
filename
;
mrb_sym
filename_sym
;
uint32_t
line_entry_count
;
mrb_debug_line_type
line_type
;
union
{
void
*
line_ptr
;
mrb_irep_debug_info_line
*
line_flat_map
;
uint16_t
*
line_ary
;
void
*
line_ptr
;
mrb_irep_debug_info_line
*
line_flat_map
;
uint16_t
*
line_ary
;
};
}
mrb_irep_debug_info_file
;
typedef
struct
mrb_irep_debug_info
{
uint32_t
pc_count
;
uint16_t
flen
;
mrb_irep_debug_info_file
**
files
;
mrb_irep_debug_info_file
**
files
;
}
mrb_irep_debug_info
;
struct
mrb_irep
;
struct
mrb_state
;
/*
* get line from irep's debug info and program counter
* @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
* @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
(
struct
mrb_state
*
mrb
,
struct
mrb_irep
*
irep
,
mrb_irep_debug_info_file
*
mrb_debug_info_append_file
(
mrb_state
*
mrb
,
mrb_irep
*
irep
,
uint32_t
start_pos
,
uint32_t
end_pos
);
mrb_irep_debug_info
*
mrb_debug_info_alloc
(
struct
mrb_state
*
mrb
,
struct
mrb_irep
*
irep
);
void
mrb_debug_info_free
(
struct
mrb_state
*
mrb
,
mrb_irep_debug_info
*
d
);
mrb_irep_debug_info
*
mrb_debug_info_alloc
(
mrb_state
*
mrb
,
mrb_irep
*
irep
);
void
mrb_debug_info_free
(
mrb_state
*
mrb
,
mrb_irep_debug_info
*
d
);
#if defined(__cplusplus)
}
/* extern "C" { */
...
...
src/debug.c
View file @
b8d5f0f6
#include "mruby/debug.h"
#include <string.h>
#include "mruby.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
const
pc
)
static
mrb_irep_debug_info_file
*
get_file
(
mrb_irep_debug_info
*
info
,
uint32_t
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
mrb_irep_debug_info_file
**
ret
=
info
->
files
;
int32_t
count
=
info
->
flen
;
ret
=
info
->
files
;
count
=
info
->
flen
;
while
(
count
>
0
)
{
int32_t
const
step
=
count
/
2
;
mrb_irep_debug_info_file
**
const
it
=
ret
+
step
;
int32_t
step
=
count
/
2
;
mrb_irep_debug_info_file
**
it
=
ret
+
step
;
if
(
!
(
pc
<
(
*
it
)
->
start_pos
))
{
ret
=
it
+
1
;
count
-=
step
+
1
;
...
...
@@ -33,7 +33,7 @@ get_file(mrb_irep_debug_info* info, uint32_t const pc)
}
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
;
int
prev_line
=
-
1
;
...
...
@@ -48,7 +48,7 @@ select_line_type(uint16_t const* lines, size_t lines_len)
}
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
)
{
mrb_irep_debug_info_file
*
f
=
NULL
;
...
...
@@ -61,7 +61,7 @@ mrb_debug_get_filename(mrb_irep* irep, uint32_t pc)
}
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
)
{
mrb_irep_debug_info_file
*
f
=
NULL
;
...
...
@@ -76,11 +76,11 @@ mrb_debug_get_line(mrb_irep* irep, uint32_t const pc)
case
mrb_debug_line_flat_map
:
{
// get upper bound
mrb_irep_debug_info_line
*
ret
=
f
->
line_flat_map
;
int32_t
count
=
f
->
line_entry_count
;
mrb_irep_debug_info_line
*
ret
=
f
->
line_flat_map
;
u
int32_t
count
=
f
->
line_entry_count
;
while
(
count
>
0
)
{
int32_t
const
step
=
count
/
2
;
mrb_irep_debug_info_line
*
const
it
=
ret
+
step
;
int32_t
step
=
count
/
2
;
mrb_irep_debug_info_line
*
it
=
ret
+
step
;
if
(
!
(
pc
<
it
->
start_pos
))
{
ret
=
it
+
1
;
count
-=
step
+
1
;
...
...
@@ -89,7 +89,7 @@ mrb_debug_get_line(mrb_irep* irep, uint32_t const pc)
--
ret
;
mrb_assert
((
ret
-
f
->
line_flat_map
)
<
f
->
line_entry_count
);
mrb_assert
((
ret
-
f
->
line_flat_map
)
<
(
ptrdiff_t
)
f
->
line_entry_count
);
mrb_assert
(
ret
->
start_pos
<=
pc
&&
pc
<
(((
ret
+
1
-
f
->
line_flat_map
)
<
f
->
line_entry_count
)
?
(
ret
+
1
)
->
start_pos
:
irep
->
debug_info
->
pc_count
));
...
...
@@ -102,49 +102,56 @@ mrb_debug_get_line(mrb_irep* irep, uint32_t const pc)
return
-
1
;
}
mrb_irep_debug_info
*
mrb_debug_info_alloc
(
mrb_state
*
mrb
,
mrb_irep
*
irep
)
mrb_irep_debug_info
*
mrb_debug_info_alloc
(
mrb_state
*
mrb
,
mrb_irep
*
irep
)
{
static
mrb_irep_debug_info
const
initial
=
{
0
,
0
,
NULL
};
mrb_
assert
(
!
irep
->
debug_info
)
;
static
const
mrb_irep_debug_info
initial
=
{
0
,
0
,
NULL
};
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
;
irep
->
debug_info
=
ret
;
return
ret
;
}
mrb_irep_debug_info_file
*
mrb_debug_info_append_file
(
mrb_state
*
mrb
,
mrb_irep
*
irep
,
uint32_t
const
start_pos
,
uint32_t
cons
t
end_pos
)
mrb_irep_debug_info_file
*
mrb_debug_info_append_file
(
mrb_state
*
mrb
,
mrb_irep
*
irep
,
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
;
}
mrb_assert
(
irep
->
filename
);
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
)
{
return
NULL
;
}
mrb_irep_debug_info_file
*
const
ret
=
(
mrb_irep_debug_info_file
*
)
mrb_malloc
(
mrb
,
sizeof
(
mrb_irep_debug_info_file
));
ret
=
(
mrb_irep_debug_info_file
*
)
mrb_malloc
(
mrb
,
sizeof
(
*
ret
));
info
->
files
=
(
mrb_irep_debug_info_file
*
)
info
->
files
?
mrb_realloc
(
mrb
,
info
->
files
,
sizeof
(
mrb_irep_debug_info_file
*
)
*
(
info
->
flen
+
1
))
:
mrb_malloc
(
mrb
,
sizeof
(
mrb_irep_debug_info_file
*
));
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
;
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
);
size_t
len
=
0
;
len
=
0
;
ret
->
filename
=
mrb_sym2name_len
(
mrb
,
ret
->
filename_sym
,
&
len
);
ret
->
line_type
=
select_line_type
(
irep
->
lines
+
start_pos
,
end_pos
-
start_pos
);
...
...
@@ -154,24 +161,24 @@ mrb_debug_info_append_file(mrb_state* mrb, mrb_irep* irep,
case
mrb_debug_line_ary
:
ret
->
line_entry_count
=
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
)
{
ret
->
line_ary
[
i
]
=
irep
->
lines
[
start_pos
+
i
];
}
break
;
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_entry_count
=
0
;
uint16_t
prev_line
=
0
;
uint32_t
i
;
for
(
i
=
0
;
i
<
file_pc_count
;
++
i
)
{
if
(
irep
->
lines
[
start_pos
+
i
]
==
prev_line
)
{
continue
;
}
ret
->
line_flat_map
=
mrb_realloc
(
mrb
,
ret
->
line_flat_map
,
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
;
// update
...
...
@@ -187,11 +194,12 @@ mrb_debug_info_append_file(mrb_state* mrb, mrb_irep* irep,
}
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
;
}
uint32_t
i
;
for
(
i
=
0
;
i
<
d
->
flen
;
++
i
)
{
mrb_assert
(
d
->
files
[
i
]);
mrb_free
(
mrb
,
d
->
files
[
i
]
->
line_ptr
);
...
...
src/dump.c
View file @
b8d5f0f6
...
...
@@ -390,14 +390,14 @@ mrb_write_section_lineno(mrb_state *mrb, size_t start_index, uint8_t *bin)
}
static
size_t
get_debug_record_size
(
mrb_state
*
mrb
,
mrb_irep
*
irep
)
{
(
void
)
mrb
;
get_debug_record_size
(
mrb_state
*
mrb
,
mrb_irep
*
irep
)
{
size_t
ret
=
0
;
uint32_t
f_idx
;
ret
+=
sizeof
(
uint32_t
);
// record size
ret
+=
sizeof
(
uint16_t
);
// file count
uint32_t
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
];
...
...
@@ -424,8 +424,10 @@ get_debug_record_size(mrb_state* mrb, mrb_irep *irep) {
}
static
int
find_filename_index
(
mrb_sym
const
*
ary
,
size_t
ary_len
,
mrb_sym
s
)
{
mrb_int
i
;
find_filename_index
(
const
mrb_sym
*
ary
,
size_t
ary_len
,
mrb_sym
s
)
{
size_t
i
;
for
(
i
=
0
;
i
<
ary_len
;
++
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) {
}
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
uint32_t
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
cur
+=
uint32_to_bin
(
file
->
start_pos
,
cur
);
// filename index
int
const
filename_idx
=
find_filename_index
(
filenames
,
filenames_len
,
filename_idx
=
find_filename_index
(
filenames
,
filenames_len
,
file
->
filename_sym
);
mrb_assert
(
filename_idx
!=
-
1
);
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
}
}
size_t
const
ret
=
cur
-
bin
;
ret
=
cur
-
bin
;
uint32_to_bin
(
ret
,
bin
);
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
}
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
;
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
)
{
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
);
section_size
+=
sizeof
(
struct
rite_section_debug_header
);
// filename table
mrb_sym
*
filenames
=
(
mrb_sym
*
)
mrb_malloc
(
mrb
,
sizeof
(
mrb_sym
*
)
*
1
);
size_t
filenames_len
=
0
;
uint8_t
*
const
filenames_len_out
=
cur
;
filenames
=
(
mrb_sym
*
)
mrb_malloc
(
mrb
,
sizeof
(
mrb_sym
*
)
*
1
);
filenames_len
=
0
;
filenames_len_out
=
cur
;
cur
+=
sizeof
(
uint16_t
);
section_size
+=
sizeof
(
uint16_t
);
size_t
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
)
{
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
;
// register filename
...
...
@@ -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
;
// filename
uint16_t
const
fn_len
=
strlen
(
file
->
filename
);
fn_len
=
(
uint16_t
)
strlen
(
file
->
filename
);
cur
+=
uint16_to_bin
(
fn_len
,
cur
);
memcpy
(
cur
,
file
->
filename
,
fn_len
);
cur
+=
fn_len
;
...
...
@@ -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
);
// records
size_t
i
;
for
(
i
=
start_index
;
i
<
mrb
->
irep_len
;
++
i
)
{
uint32_t
rlen
=
write_debug_record
(
mrb
,
mrb
->
irep
[
i
],
cur
,
filenames
,
filenames_len
);
cur
+=
rlen
;
...
...
@@ -545,9 +556,9 @@ mrb_write_section_debug(mrb_state* mrb, size_t start_index, uint8_t *cur)
}
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
;
size_t
offset
;
...
...
@@ -564,7 +575,8 @@ write_rite_binary_header(mrb_state *mrb, size_t binary_size, uint8_t* bin)
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
;
for
(
i
=
start_index
;
i
<
mrb
->
irep_len
;
++
i
)
{
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,
/* DEBUG section size */
if
(
debug_info
)
{
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
);
// filename table
mrb_sym
*
filenames
=
mrb_malloc
(
mrb
,
sizeof
(
mrb_sym
*
)
+
1
);
size_t
filenames_len
=
0
;
filenames
=
(
mrb_sym
*
)
mrb_malloc
(
mrb
,
sizeof
(
mrb_sym
*
)
+
1
);
filenames_len
=
0
;
// filename table size
section_lineno_size
+=
sizeof
(
uint16_t
);
size_t
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
)
{
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
;
// 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
;
// filename
size_t
filename_len
;
mrb_sym2name_len
(
mrb
,
file
->
filename_sym
,
&
filename_len
);
section_lineno_size
+=
sizeof
(
uint16_t
)
+
filename_len
;
}
...
...
src/load.c
View file @
b8d5f0f6
...
...
@@ -300,51 +300,60 @@ error_exit:
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
)
{
uint8_t
const
*
bin
=
start
;
mrb_irep
*
const
irep
=
mrb
->
irep
[
irepno
];
static
int
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
)
{
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
;
}
irep
->
debug_info
=
(
mrb_irep_debug_info
*
)
mrb_malloc
(
mrb
,
sizeof
(
mrb_irep_debug_info
));
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
->
files
=
(
mrb_irep_debug_info_file
**
)
mrb_malloc
(
mrb
,
sizeof
(
mrb_irep_debug_info
*
)
*
irep
->
debug_info
->
flen
);
bin
+=
sizeof
(
uint16_t
);
uint16_t
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
;
file
->
start_pos
=
bin_to_uint32
(
bin
);
bin
+=
sizeof
(
uint32_t
);
// filename
uint16_t
const
filename_idx
=
bin_to_uint16
(
bin
);
filename_idx
=
bin_to_uint16
(
bin
);
bin
+=
sizeof
(
uint16_t
);
mrb_assert
(
filename_idx
<
filenames_len
);
file
->
filename_sym
=
filenames
[
filename_idx
];
size_t
len
=
0
;
len
=
0
;
file
->
filename
=
mrb_sym2name_len
(
mrb
,
file
->
filename_sym
,
&
len
);
file
->
line_entry_count
=
bin_to_uint32
(
bin
);
bin
+=
sizeof
(
uint32_t
);
file
->
line_type
=
bin_to_uint8
(
bin
);
bin
+=
sizeof
(
uint8_t
);
switch
(
file
->
line_type
)
{
case
mrb_debug_line_ary
:
{
file
->
line_ary
=
mrb_malloc
(
mrb
,
sizeof
(
uint16_t
)
*
file
->
line_entry_count
);
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
)
{
file
->
line_ary
[
l
]
=
bin_to_uint16
(
bin
);
bin
+=
sizeof
(
uint16_t
);
}
}
break
;
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
;
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
)
{
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
);
...
...
@@ -365,24 +374,29 @@ static int read_rite_debug_record(mrb_state* mrb, uint8_t const *start, size_t i
}
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
;
struct
rite_section_debug_header
const
*
header
=
(
struct
rite_section_debug_header
const
*
)
bin
;
bin
+=
sizeof
(
struct
rite_section_debug_header
);
const
uint8_t
*
bin
;
struct
rite_section_debug_header
*
header
;
uint16_t
i
;
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
);
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
)
{
uint16_t
const
f_len
=
bin_to_uint16
(
bin
);
uint16_t
f_len
=
bin_to_uint16
(
bin
);
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
;
}
...
...
src/parse.y
View file @
b8d5f0f6
...
...
@@ -5185,14 +5185,17 @@ mrbc_partial_hook(mrb_state *mrb, mrbc_context *c, int (*func)(struct mrb_parser
}
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 i;
mrb_sym* new_table;
sym = mrb_intern_cstr(p->mrb, f);
p->filename = mrb_sym2name_len(p->mrb, sym, &len);
p->lineno = (p->filename_table_length > 0)? 0 : 1;
size_t i;
for(i = 0; i < p->filename_table_length; ++i) {
if(p->filename_table[i] == sym) {
p->current_filename_index = i;
...
...
@@ -5202,7 +5205,7 @@ mrb_parser_set_filename(struct mrb_parser_state* p, char const* f)
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) {
memcpy(new_table, p->filename_table, sizeof(mrb_sym) * p->filename_table_length);
}
...
...
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