Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
c560c645
Commit
c560c645
authored
Nov 16, 2015
by
antirez
Browse files
Lua debugger: trace command implemented.
parent
22959e07
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/scripting.c
View file @
c560c645
...
...
@@ -2145,6 +2145,26 @@ void ldbRedis(lua_State *lua, sds *argv, int argc) {
lua_pop
(
lua
,
2
);
/* Discard the result and clean the stack. */
}
/* Implements "trace" command of the Lua debugger. It just prints a backtrace
* querying Lua starting from the current callframe back to the outer one. */
void
ldbTrace
(
lua_State
*
lua
)
{
lua_Debug
ar
;
int
level
=
0
;
while
(
lua_getstack
(
lua
,
level
,
&
ar
))
{
lua_getinfo
(
lua
,
"Snl"
,
&
ar
);
if
(
strstr
(
ar
.
short_src
,
"user_script"
)
==
NULL
)
continue
;
ldbLog
(
sdscatprintf
(
sdsempty
(),
"%s %s:"
,
(
level
==
0
)
?
"In"
:
"From"
,
ar
.
name
?
ar
.
name
:
"top level"
));
ldbLogSourceLine
(
ar
.
currentline
);
level
++
;
}
if
(
level
==
0
)
{
ldbLog
(
sdsnew
(
"<error> Can't retrieve Lua stack."
));
}
}
/* Read debugging commands from client. */
void
ldbRepl
(
lua_State
*
lua
)
{
sds
*
argv
;
...
...
@@ -2190,6 +2210,7 @@ ldbLog(sdsnew("[b]reak Show all breakpoints."));
ldbLog
(
sdsnew
(
"[b]reak <line> Add a breakpoint to the specified line."
));
ldbLog
(
sdsnew
(
"[b]reak -<line> Remove breakpoint from the specified line."
));
ldbLog
(
sdsnew
(
"[b]reak 0 Remove all breakpoints."
));
ldbLog
(
sdsnew
(
"[t]race Show a backtrace."
));
ldbLog
(
sdsnew
(
"[e]eval <code> Execute some Lua code (in a different callframe)."
));
ldbLog
(
sdsnew
(
"[r]edis <cmd> Execute a Redis command."
));
ldbLog
(
sdsnew
(
"[a]abort Stop the execution of the script. In sync"
));
...
...
@@ -2206,6 +2227,9 @@ ldbLog(sdsnew(" in the next line of code."));
break
;
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"c"
)
||
!
strcasecmp
(
argv
[
0
],
"continue"
)){
break
;
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"t"
)
||
!
strcasecmp
(
argv
[
0
],
"trace"
))
{
ldbTrace
(
lua
);
ldbSendLogs
();
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"b"
)
||
!
strcasecmp
(
argv
[
0
],
"break"
))
{
ldbBreak
(
argv
,
argc
);
ldbSendLogs
();
...
...
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