Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
136b149e
Commit
136b149e
authored
Jan 19, 2014
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
py: Add full traceback to exception printing.
parent
49f6a99c
No related branches found
No related tags found
No related merge requests found
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
py/obj.c
+16
-0
16 additions, 0 deletions
py/obj.c
py/obj.h
+3
-2
3 additions, 2 deletions
py/obj.h
py/objexcept.c
+18
-20
18 additions, 20 deletions
py/objexcept.c
py/vm.c
+1
-1
1 addition, 1 deletion
py/vm.c
stm/main.c
+2
-4
2 additions, 4 deletions
stm/main.c
unix/main.c
+1
-9
1 addition, 9 deletions
unix/main.c
with
41 additions
and
36 deletions
py/obj.c
+
16
−
0
View file @
136b149e
...
...
@@ -58,6 +58,22 @@ void mp_obj_print(mp_obj_t o_in, mp_print_kind_t kind) {
mp_obj_print_helper
(
printf_wrapper
,
NULL
,
o_in
,
kind
);
}
// helper function to print an exception with traceback
void
mp_obj_print_exception
(
mp_obj_t
exc
)
{
if
(
MP_OBJ_IS_TYPE
(
exc
,
&
exception_type
))
{
machine_uint_t
n
,
*
values
;
mp_obj_exception_get_traceback
(
exc
,
&
n
,
&
values
);
if
(
n
>
0
)
{
printf
(
"Traceback (most recent call last):
\n
"
);
for
(
int
i
=
n
-
3
;
i
>=
0
;
i
-=
3
)
{
printf
(
" File
\"
%s
\"
, line %d, in %s
\n
"
,
qstr_str
(
values
[
i
]),
(
int
)
values
[
i
+
1
],
qstr_str
(
values
[
i
+
2
]));
}
}
}
mp_obj_print
(
exc
,
PRINT_REPR
);
printf
(
"
\n
"
);
}
bool
mp_obj_is_callable
(
mp_obj_t
o_in
)
{
if
(
MP_OBJ_IS_SMALL_INT
(
o_in
))
{
return
false
;
...
...
This diff is collapsed.
Click to expand it.
py/obj.h
+
3
−
2
View file @
136b149e
...
...
@@ -236,6 +236,7 @@ const char *mp_obj_get_type_str(mp_obj_t o_in);
void
mp_obj_print_helper
(
void
(
*
print
)(
void
*
env
,
const
char
*
fmt
,
...),
void
*
env
,
mp_obj_t
o_in
,
mp_print_kind_t
kind
);
void
mp_obj_print
(
mp_obj_t
o
,
mp_print_kind_t
kind
);
void
mp_obj_print_exception
(
mp_obj_t
exc
);
bool
mp_obj_is_callable
(
mp_obj_t
o_in
);
machine_int_t
mp_obj_hash
(
mp_obj_t
o_in
);
...
...
@@ -273,8 +274,8 @@ machine_int_t mp_obj_int_get_checked(mp_obj_t self_in);
// exception
extern
const
mp_obj_type_t
exception_type
;
qstr
mp_obj_exception_get_type
(
mp_obj_t
self_in
);
void
mp_obj_exception_
set_source_info
(
mp_obj_t
self_in
,
qstr
file
,
machine_uint_t
line
,
qstr
block
);
void
mp_obj_exception_get_
source_info
(
mp_obj_t
self_in
,
qstr
*
file
,
machine_uint_t
*
line
,
qstr
*
block
);
void
mp_obj_exception_
add_traceback
(
mp_obj_t
self_in
,
qstr
file
,
machine_uint_t
line
,
qstr
block
);
void
mp_obj_exception_get_
traceback
(
mp_obj_t
self_in
,
machine_uint_t
*
n
,
machine_uint_t
*
*
values
);
// str
extern
const
mp_obj_type_t
str_type
;
...
...
This diff is collapsed.
Click to expand it.
py/objexcept.c
+
18
−
20
View file @
136b149e
...
...
@@ -17,9 +17,7 @@
// have args tuple (or otherwise have it as NULL).
typedef
struct
mp_obj_exception_t
{
mp_obj_base_t
base
;
qstr
source_file
;
machine_uint_t
source_line
;
qstr
source_block
;
mp_obj_t
traceback
;
// a list object, holding (file,line,block) as numbers (not Python objects); a hack for now
qstr
id
;
qstr
msg
;
mp_obj_tuple_t
args
;
...
...
@@ -90,8 +88,7 @@ mp_obj_t mp_obj_new_exception_msg_varg(qstr id, const char *fmt, ...) {
// make exception object
mp_obj_exception_t
*
o
=
m_new_obj_var
(
mp_obj_exception_t
,
mp_obj_t
*
,
0
);
o
->
base
.
type
=
&
exception_type
;
o
->
source_file
=
0
;
o
->
source_line
=
0
;
o
->
traceback
=
MP_OBJ_NULL
;
o
->
id
=
id
;
o
->
args
.
len
=
0
;
if
(
fmt
==
NULL
)
{
...
...
@@ -115,26 +112,27 @@ qstr mp_obj_exception_get_type(mp_obj_t self_in) {
return
self
->
id
;
}
void
mp_obj_exception_
set_source_info
(
mp_obj_t
self_in
,
qstr
file
,
machine_uint_t
line
,
qstr
block
)
{
void
mp_obj_exception_
add_traceback
(
mp_obj_t
self_in
,
qstr
file
,
machine_uint_t
line
,
qstr
block
)
{
assert
(
MP_OBJ_IS_TYPE
(
self_in
,
&
exception_type
));
mp_obj_exception_t
*
self
=
self_in
;
// TODO make a list of file/line pairs for the traceback
// for now, just keep the first one
if
(
file
!=
0
&&
self
->
source_file
==
0
)
{
self
->
source_file
=
file
;
}
if
(
line
!=
0
&&
self
->
source_line
==
0
)
{
self
->
source_line
=
line
;
}
if
(
block
!=
0
&&
self
->
source_block
==
0
)
{
self
->
source_block
=
block
;
// for traceback, we are just using the list object for convenience, it's not really a list of Python objects
if
(
self
->
traceback
==
MP_OBJ_NULL
)
{
self
->
traceback
=
mp_obj_new_list
(
0
,
NULL
);
}
mp_obj_list_append
(
self
->
traceback
,
(
mp_obj_t
)(
machine_uint_t
)
file
);
mp_obj_list_append
(
self
->
traceback
,
(
mp_obj_t
)(
machine_uint_t
)
line
);
mp_obj_list_append
(
self
->
traceback
,
(
mp_obj_t
)(
machine_uint_t
)
block
);
}
void
mp_obj_exception_get_
source_info
(
mp_obj_t
self_in
,
qstr
*
file
,
machine_uint_t
*
line
,
qstr
*
block
)
{
void
mp_obj_exception_get_
traceback
(
mp_obj_t
self_in
,
machine_uint_t
*
n
,
machine_uint_t
*
*
values
)
{
assert
(
MP_OBJ_IS_TYPE
(
self_in
,
&
exception_type
));
mp_obj_exception_t
*
self
=
self_in
;
*
file
=
self
->
source_file
;
*
line
=
self
->
source_line
;
*
block
=
self
->
source_block
;
if
(
self
->
traceback
==
MP_OBJ_NULL
)
{
*
n
=
0
;
*
values
=
NULL
;
}
else
{
uint
n2
;
mp_obj_list_get
(
self
->
traceback
,
&
n2
,
(
mp_obj_t
**
)
values
);
*
n
=
n2
;
}
}
This diff is collapsed.
Click to expand it.
py/vm.c
+
1
−
1
View file @
136b149e
...
...
@@ -544,7 +544,7 @@ bool mp_execute_byte_code_2(const byte *code_info, const byte **ip_in_out, mp_ob
break
;
}
}
mp_obj_exception_
set_source_info
(
nlr
.
ret_val
,
source_file
,
source_line
,
block_name
);
mp_obj_exception_
add_traceback
(
nlr
.
ret_val
,
source_file
,
source_line
,
block_name
);
}
while
(
currently_in_except_block
)
{
...
...
This diff is collapsed.
Click to expand it.
stm/main.c
+
2
−
4
View file @
136b149e
...
...
@@ -445,8 +445,7 @@ void do_repl(void) {
}
}
else
{
// uncaught exception
mp_obj_print
((
mp_obj_t
)
nlr
.
ret_val
,
PRINT_REPR
);
printf
(
"
\n
"
);
mp_obj_print_exception
((
mp_obj_t
)
nlr
.
ret_val
);
}
}
}
...
...
@@ -490,8 +489,7 @@ bool do_file(const char *filename) {
return
true
;
}
else
{
// uncaught exception
mp_obj_print
((
mp_obj_t
)
nlr
.
ret_val
,
PRINT_REPR
);
printf
(
"
\n
"
);
mp_obj_print_exception
((
mp_obj_t
)
nlr
.
ret_val
);
return
false
;
}
}
...
...
This diff is collapsed.
Click to expand it.
unix/main.c
+
1
−
9
View file @
136b149e
...
...
@@ -73,15 +73,7 @@ static void execute_from_lexer(mp_lexer_t *lex, mp_parse_input_kind_t input_kind
nlr_pop
();
}
else
{
// uncaught exception
mp_obj_t
exc
=
(
mp_obj_t
)
nlr
.
ret_val
;
if
(
MP_OBJ_IS_TYPE
(
exc
,
&
exception_type
))
{
qstr
file
,
block
;
machine_uint_t
line
;
mp_obj_exception_get_source_info
(
exc
,
&
file
,
&
line
,
&
block
);
printf
(
"File
\"
%s
\"
, line %d, in %s
\n
"
,
qstr_str
(
file
),
(
int
)
line
,
qstr_str
(
block
));
}
mp_obj_print
(
exc
,
PRINT_REPR
);
printf
(
"
\n
"
);
mp_obj_print_exception
((
mp_obj_t
)
nlr
.
ret_val
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment