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
4c1667a5
Unverified
Commit
4c1667a5
authored
Dec 18, 2019
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
Dec 18, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4879 from shuujii/refine-output-of-mrb_print_error
Refine output of `mrb_print_error()`
parents
f507ff48
29ecc384
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
47 deletions
+31
-47
src/backtrace.c
src/backtrace.c
+28
-43
src/error.c
src/error.c
+3
-3
src/print.c
src/print.c
+0
-1
No files found.
src/backtrace.c
View file @
4c1667a5
...
@@ -25,6 +25,10 @@ typedef void (*each_backtrace_func)(mrb_state*, const struct backtrace_location*
...
@@ -25,6 +25,10 @@ typedef void (*each_backtrace_func)(mrb_state*, const struct backtrace_location*
static
const
mrb_data_type
bt_type
=
{
"Backtrace"
,
mrb_free
};
static
const
mrb_data_type
bt_type
=
{
"Backtrace"
,
mrb_free
};
mrb_value
mrb_exc_to_s
(
mrb_state
*
mrb
,
mrb_value
exc
);
mrb_value
mrb_mod_to_s
(
mrb_state
*
mrb
,
mrb_value
klass
);
mrb_value
mrb_unpack_backtrace
(
mrb_state
*
mrb
,
mrb_value
backtrace
);
static
void
static
void
each_backtrace
(
mrb_state
*
mrb
,
ptrdiff_t
ciidx
,
const
mrb_code
*
pc0
,
each_backtrace_func
func
,
void
*
data
)
each_backtrace
(
mrb_state
*
mrb
,
ptrdiff_t
ciidx
,
const
mrb_code
*
pc0
,
each_backtrace_func
func
,
void
*
data
)
{
{
...
@@ -74,50 +78,35 @@ each_backtrace(mrb_state *mrb, ptrdiff_t ciidx, const mrb_code *pc0, each_backtr
...
@@ -74,50 +78,35 @@ each_backtrace(mrb_state *mrb, ptrdiff_t ciidx, const mrb_code *pc0, each_backtr
#ifndef MRB_DISABLE_STDIO
#ifndef MRB_DISABLE_STDIO
static
void
static
void
print_backtrace
(
mrb_state
*
mrb
,
mrb_value
backtrace
)
print_backtrace
(
mrb_state
*
mrb
,
struct
RObject
*
exc
,
mrb_value
backtrace
)
{
{
int
i
;
int
i
;
mrb_int
n
;
mrb_int
n
=
RARRAY_LEN
(
backtrace
);
mrb_value
*
loc
,
mesg
,
cname
;
FILE
*
stream
=
stderr
;
FILE
*
stream
=
stderr
;
n
=
RARRAY_LEN
(
backtrace
)
-
1
;
if
(
n
!=
0
)
{
if
(
n
==
0
)
return
;
fprintf
(
stream
,
"trace (most recent call last):
\n
"
);
for
(
i
=
n
-
1
,
loc
=&
RARRAY_PTR
(
backtrace
)[
i
];
i
>
0
;
i
--
,
loc
--
)
{
fprintf
(
stream
,
"trace (most recent call last):
\n
"
);
if
(
mrb_string_p
(
*
loc
))
{
for
(
i
=
0
;
i
<
n
;
i
++
)
{
fprintf
(
stream
,
"
\t
[%d] %.*s
\n
"
,
mrb_value
entry
=
RARRAY_PTR
(
backtrace
)[
n
-
i
-
1
];
i
,
(
int
)
RSTRING_LEN
(
*
loc
),
RSTRING_PTR
(
*
loc
));
}
if
(
mrb_string_p
(
entry
))
{
fprintf
(
stream
,
"
\t
[%d] %.*s
\n
"
,
i
,
(
int
)
RSTRING_LEN
(
entry
),
RSTRING_PTR
(
entry
));
}
}
}
}
}
static
void
if
(
n
!=
0
)
{
print_packed_backtrace
(
mrb_state
*
mrb
,
mrb_value
packed
)
fprintf
(
stream
,
"%.*s: "
,
(
int
)
RSTRING_LEN
(
*
loc
),
RSTRING_PTR
(
*
loc
));
{
}
FILE
*
stream
=
stderr
;
mesg
=
mrb_exc_to_s
(
mrb
,
mrb_obj_value
(
exc
));
const
struct
backtrace_location
*
bt
;
cname
=
mrb_mod_to_s
(
mrb
,
mrb_obj_value
(
exc
->
c
));
int
n
,
i
;
if
(
RSTRING_LEN
(
mesg
)
==
0
)
{
int
ai
=
mrb_gc_arena_save
(
mrb
);
fprintf
(
stream
,
"%.*s
\n
"
,
(
int
)
RSTRING_LEN
(
cname
),
RSTRING_PTR
(
cname
));
}
bt
=
(
struct
backtrace_location
*
)
mrb_data_check_get_ptr
(
mrb
,
packed
,
&
bt_type
);
else
{
if
(
bt
==
NULL
)
return
;
fprintf
(
stream
,
"%.*s (%.*s)
\n
"
,
n
=
(
int
)
RDATA
(
packed
)
->
flags
;
(
int
)
RSTRING_LEN
(
mesg
),
RSTRING_PTR
(
mesg
),
if
(
n
==
0
)
return
;
(
int
)
RSTRING_LEN
(
cname
),
RSTRING_PTR
(
cname
));
fprintf
(
stream
,
"trace (most recent call last):
\n
"
);
for
(
i
=
0
;
i
<
n
;
i
++
)
{
const
struct
backtrace_location
*
entry
=
&
bt
[
n
-
i
-
1
];
fprintf
(
stream
,
"
\t
[%d] %s:%d"
,
i
,
entry
->
filename
,
(
int
)
entry
->
lineno
);
if
(
entry
->
method_id
!=
0
)
{
const
char
*
method_name
;
method_name
=
mrb_sym_name
(
mrb
,
entry
->
method_id
);
fprintf
(
stream
,
":in %s"
,
method_name
);
mrb_gc_arena_restore
(
mrb
,
ai
);
}
fprintf
(
stream
,
"
\n
"
);
}
}
}
}
...
@@ -137,12 +126,8 @@ mrb_print_backtrace(mrb_state *mrb)
...
@@ -137,12 +126,8 @@ mrb_print_backtrace(mrb_state *mrb)
backtrace
=
mrb_obj_iv_get
(
mrb
,
mrb
->
exc
,
mrb_intern_lit
(
mrb
,
"backtrace"
));
backtrace
=
mrb_obj_iv_get
(
mrb
,
mrb
->
exc
,
mrb_intern_lit
(
mrb
,
"backtrace"
));
if
(
mrb_nil_p
(
backtrace
))
return
;
if
(
mrb_nil_p
(
backtrace
))
return
;
if
(
mrb_array_p
(
backtrace
))
{
if
(
!
mrb_array_p
(
backtrace
))
backtrace
=
mrb_unpack_backtrace
(
mrb
,
backtrace
);
print_backtrace
(
mrb
,
backtrace
);
print_backtrace
(
mrb
,
mrb
->
exc
,
backtrace
);
}
else
{
print_packed_backtrace
(
mrb
,
backtrace
);
}
}
}
#else
#else
...
...
src/error.c
View file @
4c1667a5
...
@@ -88,8 +88,8 @@ exc_exception(mrb_state *mrb, mrb_value self)
...
@@ -88,8 +88,8 @@ exc_exception(mrb_state *mrb, mrb_value self)
* no message is set).
* no message is set).
*/
*/
static
mrb_value
mrb_value
exc_to_s
(
mrb_state
*
mrb
,
mrb_value
exc
)
mrb_
exc_to_s
(
mrb_state
*
mrb
,
mrb_value
exc
)
{
{
mrb_value
mesg
=
mrb_attr_get
(
mrb
,
exc
,
mrb_intern_lit
(
mrb
,
"mesg"
));
mrb_value
mesg
=
mrb_attr_get
(
mrb
,
exc
,
mrb_intern_lit
(
mrb
,
"mesg"
));
struct
RObject
*
p
;
struct
RObject
*
p
;
...
@@ -596,7 +596,7 @@ mrb_init_exception(mrb_state *mrb)
...
@@ -596,7 +596,7 @@ mrb_init_exception(mrb_state *mrb)
mrb_define_class_method
(
mrb
,
exception
,
"exception"
,
mrb_instance_new
,
MRB_ARGS_OPT
(
1
));
mrb_define_class_method
(
mrb
,
exception
,
"exception"
,
mrb_instance_new
,
MRB_ARGS_OPT
(
1
));
mrb_define_method
(
mrb
,
exception
,
"exception"
,
exc_exception
,
MRB_ARGS_OPT
(
1
));
mrb_define_method
(
mrb
,
exception
,
"exception"
,
exc_exception
,
MRB_ARGS_OPT
(
1
));
mrb_define_method
(
mrb
,
exception
,
"initialize"
,
exc_initialize
,
MRB_ARGS_OPT
(
1
));
mrb_define_method
(
mrb
,
exception
,
"initialize"
,
exc_initialize
,
MRB_ARGS_OPT
(
1
));
mrb_define_method
(
mrb
,
exception
,
"to_s"
,
exc_to_s
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
exception
,
"to_s"
,
mrb_exc_to_s
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
exception
,
"message"
,
exc_message
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
exception
,
"message"
,
exc_message
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
exception
,
"inspect"
,
exc_inspect
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
exception
,
"inspect"
,
exc_inspect
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
exception
,
"backtrace"
,
mrb_exc_backtrace
,
MRB_ARGS_NONE
());
mrb_define_method
(
mrb
,
exception
,
"backtrace"
,
mrb_exc_backtrace
,
MRB_ARGS_NONE
());
...
...
src/print.c
View file @
4c1667a5
...
@@ -31,7 +31,6 @@ MRB_API void
...
@@ -31,7 +31,6 @@ MRB_API void
mrb_print_error
(
mrb_state
*
mrb
)
mrb_print_error
(
mrb_state
*
mrb
)
{
{
mrb_print_backtrace
(
mrb
);
mrb_print_backtrace
(
mrb
);
printstr
(
mrb_funcall
(
mrb
,
mrb_obj_value
(
mrb
->
exc
),
"inspect"
,
0
),
stderr
);
}
}
MRB_API
void
MRB_API
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