Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
- renamed inlinedfile/line -> inlinedat_file/line
- update inlining message
- fix poplinenum.
  • Loading branch information
ihnorton committed Aug 27, 2015
1 parent eb867a9 commit 19e765e
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 48 deletions.
2 changes: 2 additions & 0 deletions base/cartesian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ function poplinenum(ex::Expr)
return ex.args[1]
elseif length(ex.args) == 2 && isa(ex.args[1], LineNumberNode)
return ex.args[2]
elseif (length(ex.args) == 2 && isa(ex.args[1], Expr) && ex.args[1].head == :line)
return ex.args[2]
end
end
ex
Expand Down
2 changes: 1 addition & 1 deletion base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function firstcaller(bt::Array{Ptr{Void},1}, funcsym::Symbol)
if lkup === ()
continue
end
fname, file, line, inlined_file, inlined_line, fromC = lkup
fname, file, line, inlinedat_file, inlinedat_line, fromC = lkup
if fname == funcsym
break
end
Expand Down
36 changes: 21 additions & 15 deletions base/replutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -339,15 +339,16 @@ function show_method_candidates(io::IO, ex::MethodError)
end
end

function show_trace_entry(io, fname, file, line, inlinedfile, inlinedline, n)
print(io, "\n")
print(io, " in ", fname)

if (inlinedfile != symbol(""))
print(io, " at ", inlinedfile, ":", inlinedline)
print(io, " \n [ thrown by inlined function defined at ]\n ")
function show_trace_entry(io, fname, file, line, inlinedat_file, inlinedat_line, n)
# if we have inlining information, we print the `file`:`line` first,
# then show the inlining info, because the inlining location
# corresponds to `fname`.
if (inlinedat_file != symbol(""))
# align the location text
print(io, "\n")
print(io, " [inlined code] from ")
else
print(io, " at ")
print(io, " in ", fname, " at ")
end

print(io, file)
Expand All @@ -363,6 +364,11 @@ function show_trace_entry(io, fname, file, line, inlinedfile, inlinedline, n)
if n > 1
print(io, " (repeats ", n, " times)")
end

if (inlinedat_file != symbol(""))
print(io, "\n in ", fname, " at ")
print(io, inlinedat_file, ":", inlinedat_line, "\n")
end
end

function show_backtrace(io::IO, t, set=1:typemax(Int))
Expand All @@ -378,24 +384,24 @@ function show_backtrace(io::IO, t, set=1:typemax(Int))
end

function show_backtrace(io::IO, top_function::Symbol, t, set)
process_entry(lastname, lastfile, lastline, last_inlinedfile, last_inlinedline, n) =
show_trace_entry(io, lastname, lastfile, lastline, last_inlinedfile, last_inlinedline, n)
process_entry(lastname, lastfile, lastline, last_inlinedat_file, last_inlinedat_line, n) =
show_trace_entry(io, lastname, lastfile, lastline, last_inlinedat_file, last_inlinedat_line, n)
process_backtrace(process_entry, top_function, t, set)
end

# process the backtrace, up to (but not including) top_function
function process_backtrace(process_func::Function, top_function::Symbol, t, set)
n = 1
lastfile = ""; lastline = -11; lastname = symbol("#");
last_inlinedfile = ""; last_inlinedline = -1
last_inlinedat_file = ""; last_inlinedat_line = -1
local fname, file, line
count = 0
for i = 1:length(t)
lkup = ccall(:jl_lookup_code_address, Any, (Ptr{Void}, Cint), t[i]-1, true)
if lkup === nothing
continue
end
fname, file, line, inlinedfile, inlinedline, fromC = lkup
fname, file, line, inlinedat_file, inlinedat_line, fromC = lkup

if fromC; continue; end
if i == 1 && fname == :error; continue; end
Expand All @@ -405,16 +411,16 @@ function process_backtrace(process_func::Function, top_function::Symbol, t, set)

if file != lastfile || line != lastline || fname != lastname
if lastline != -11
process_func(lastname, lastfile, lastline, last_inlinedfile, last_inlinedline, n)
process_func(lastname, lastfile, lastline, last_inlinedat_file, last_inlinedat_line, n)
end
n = 1
lastfile = file; lastline = line; lastname = fname;
last_inlinedfile = inlinedfile; last_inlinedline = inlinedline;
last_inlinedat_file = inlinedat_file; last_inlinedat_line = inlinedat_line;
else
n += 1
end
end
if n > 1 || lastline != -11
process_func(lastname, lastfile, lastline, last_inlinedfile, last_inlinedline, n)
process_func(lastname, lastfile, lastline, last_inlinedat_file, last_inlinedat_line, n)
end
end
30 changes: 15 additions & 15 deletions src/debuginfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,8 @@ void RegisterJuliaJITEventListener()

// *name and *filename are either NULL or malloc'd pointers
void lookup_pointer(DIContext *context, char **name, size_t *line,
char **filename, size_t *inlined_line,
char **inlined_file, size_t pointer,
char **filename, size_t *inlinedat_line,
char **inlinedat_file, size_t pointer,
int demangle, int *fromC)
{
DILineInfo info, topinfo;
Expand Down Expand Up @@ -506,8 +506,8 @@ void lookup_pointer(DIContext *context, char **name, size_t *line,

if (inlineinfo.getNumberOfFrames() > 1) {
topinfo = inlineinfo.getFrame(inlineinfo.getNumberOfFrames() - 1);
jl_copy_str(inlined_file, topinfo.getFileName());
*inlined_line = topinfo.getLine();
jl_copy_str(inlinedat_file, topinfo.getFileName());
*inlinedat_line = topinfo.getLine();
}
#else
if (strcmp(info.FunctionName.c_str(), "<invalid>") == 0) goto done;
Expand All @@ -517,8 +517,8 @@ void lookup_pointer(DIContext *context, char **name, size_t *line,

if (inlineinfo.getNumberOfFrames() > 1) {
topinfo = inlineinfo.getFrame(inlineinfo.getNumberOfFrames() - 1);
jl_copy_str(inlined_file, topinfo.FileName.c_str());
*inlined_line = topinfo.getLine();
jl_copy_str(inlinedat_file, topinfo.FileName.c_str());
*inlinedat_line = topinfo.getLine();
}
#endif

Expand Down Expand Up @@ -585,7 +585,7 @@ extern "C" uint64_t jl_sysimage_base;

// *name and *filename should be either NULL or malloc'd pointer
void jl_getDylibFunctionInfo(char **name, char **filename, size_t *line,
char** inlined_file, size_t *inlined_line,
char** inlinedat_file, size_t *inlinedat_line,
size_t pointer, int *fromC, int skipC, int skipInline)
{
#ifdef _OS_WINDOWS_
Expand Down Expand Up @@ -783,7 +783,7 @@ void jl_getDylibFunctionInfo(char **name, char **filename, size_t *line,
#ifdef _OS_DARWIN_
lookup:
#endif
lookup_pointer(context, name, line, filename, inlined_line, inlined_file, pointer+slide,
lookup_pointer(context, name, line, filename, inlinedat_line, inlinedat_file, pointer+slide,
fbase == jl_sysimage_base, fromC);
}
else {
Expand All @@ -793,14 +793,14 @@ void jl_getDylibFunctionInfo(char **name, char **filename, size_t *line,

// Set *name and *filename to either NULL or malloc'd string
void jl_getFunctionInfo(char **name, char **filename, size_t *line,
char **inlined_file, size_t *inlined_line,
char **inlinedat_file, size_t *inlinedat_line,
size_t pointer, int *fromC, int skipC, int skipInline)
{
*name = NULL;
*line = -1;
*filename = NULL;
*inlined_file = NULL;
*inlined_line = -1;
*inlinedat_file = NULL;
*inlinedat_line = -1;
*fromC = 0;

#ifdef USE_MCJIT
Expand Down Expand Up @@ -830,7 +830,7 @@ void jl_getFunctionInfo(char **name, char **filename, size_t *line,
DIContext *context = DIContext::getDWARFContext(const_cast<object::ObjectFile*>(it->second.object));
#endif
#endif
lookup_pointer(context, name, line, filename, inlined_line, inlined_file, pointer, 1, fromC);
lookup_pointer(context, name, line, filename, inlinedat_line, inlinedat_file, pointer, 1, fromC);
delete context;
return;
}
Expand Down Expand Up @@ -898,14 +898,14 @@ void jl_getFunctionInfo(char **name, char **filename, size_t *line,
if ((!skipInline) && (inlinedAt != NULL)) {
DebugLoc inlineloc = DebugLoc::getFromDILocation(inlinedAt);
DILexicalBlockFile inlinescope = DILexicalBlockFile(inlineloc.getScope((*it).second.func->getContext()));
jl_copy_str(inlined_file, inlinescope.getFilename().str().c_str());
*inlined_line = inlineloc.getLine();
jl_copy_str(inlinedat_file, inlinescope.getFilename().str().c_str());
*inlinedat_line = inlineloc.getLine();
}

return;
}
#endif // USE_MCJIT
jl_getDylibFunctionInfo(name, filename, line, inlined_file, inlined_line, pointer, fromC, skipC, skipInline);
jl_getDylibFunctionInfo(name, filename, line, inlinedat_file, inlinedat_line, pointer, fromC, skipC, skipInline);
}

int jl_get_llvmf_info(uint64_t fptr, uint64_t *symsize, uint64_t *slide,
Expand Down
8 changes: 4 additions & 4 deletions src/disasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,12 @@ int OpInfoLookup(void *DisInfo, uint64_t PC,
char *name;
char *filename;
size_t line;
char *inlined_file;
size_t inlined_line;
char *inlinedat_file;
size_t inlinedat_line;
int fromC;
jl_getFunctionInfo(&name, &filename, &line, &inlined_file, &inlined_line, pointer, &fromC, skipC, 1);
jl_getFunctionInfo(&name, &filename, &line, &inlinedat_file, &inlinedat_line, pointer, &fromC, skipC, 1);
free(filename);
free(inlined_file);
free(inlinedat_file);
if (!name)
return 0; // Did not find symbolic information
// Describe the symbol
Expand Down
2 changes: 1 addition & 1 deletion src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ DLLEXPORT void attach_exception_port(void);
#endif
// Set *name and *filename to either NULL or malloc'd string
void jl_getFunctionInfo(char **name, char **filename, size_t *line,
char **inlined_file, size_t *inlined_line,
char **inlinedat_file, size_t *inlinedat_line,
uintptr_t pointer, int *fromC, int skipC, int skipInline);

// *to is NULL or malloc'd pointer, from is allowed to be NULL
Expand Down
24 changes: 12 additions & 12 deletions src/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,13 +470,13 @@ size_t bt_size = 0;
// Always Set *func_name and *file_name to malloc'd pointers (non-NULL)
static int frame_info_from_ip(char **func_name,
char **file_name, size_t *line_num,
char **inlined_file, size_t *inlined_line,
char **inlinedat_file, size_t *inlinedat_line,
size_t ip, int skipC, int skipInline)
{
static const char *name_unknown = "???";
int fromC = 0;

jl_getFunctionInfo(func_name, file_name, line_num, inlined_file, inlined_line, ip, &fromC,
jl_getFunctionInfo(func_name, file_name, line_num, inlinedat_file, inlinedat_line, ip, &fromC,
skipC, skipInline);
if (!*func_name) {
*func_name = strdup(name_unknown);
Expand Down Expand Up @@ -710,22 +710,22 @@ DLLEXPORT jl_value_t *jl_lookup_code_address(void *ip, int skipC)
char *func_name;
size_t line_num;
char *file_name;
size_t inlined_line;
char *inlined_file;
size_t inlinedat_line;
char *inlinedat_file;
int fromC = frame_info_from_ip(&func_name, &file_name, &line_num,
&inlined_file, &inlined_line, (size_t)ip, skipC, 0);
&inlinedat_file, &inlinedat_line, (size_t)ip, skipC, 0);
jl_value_t *r = (jl_value_t*)jl_alloc_svec(7);
JL_GC_PUSH1(&r);
jl_svecset(r, 0, jl_symbol(func_name));
jl_svecset(r, 1, jl_symbol(file_name));
jl_svecset(r, 2, jl_box_long(line_num));
jl_svecset(r, 3, jl_symbol(inlined_file ? inlined_file : ""));
jl_svecset(r, 4, jl_box_long(inlined_file ? inlined_line : -1));
jl_svecset(r, 3, jl_symbol(inlinedat_file ? inlinedat_file : ""));
jl_svecset(r, 4, jl_box_long(inlinedat_file ? inlinedat_line : -1));
jl_svecset(r, 5, jl_box_bool(fromC));
jl_svecset(r, 6, jl_box_long((intptr_t)ip));
free(func_name);
free(file_name);
free(inlined_file);
free(inlinedat_file);
JL_GC_POP();
return r;
}
Expand All @@ -751,9 +751,9 @@ DLLEXPORT void gdblookup(ptrint_t ip)
char *func_name;
size_t line_num;
char *file_name;
size_t inlined_line;
char *inlined_file;
frame_info_from_ip(&func_name, &file_name, &line_num, &inlined_file, &inlined_line, ip,
size_t inlinedat_line;
char *inlinedat_file;
frame_info_from_ip(&func_name, &file_name, &line_num, &inlinedat_file, &inlinedat_line, ip,
/* skipC */ 0, /* skipInline */ 1);
if (line_num == ip) {
jl_safe_printf("unknown function (ip: %p)\n", (void*)ip);
Expand All @@ -767,7 +767,7 @@ DLLEXPORT void gdblookup(ptrint_t ip)
}
free(func_name);
free(file_name);
free(inlined_file);
free(inlinedat_file);
}

DLLEXPORT void jlbacktrace()
Expand Down

0 comments on commit 19e765e

Please sign in to comment.