@@ -162,13 +162,13 @@ const char *jl_demangle(const char *name)
162
162
163
163
JuliaJITEventListener *jl_jit_events;
164
164
165
- extern " C" void jl_getFunctionInfo (const char **name, size_t *line, const char **filename, uintptr_t pointer, int skipC);
165
+ extern " C" void jl_getFunctionInfo (const char **name, size_t *line, const char **filename, uintptr_t pointer, int *fromC, int skipC);
166
166
167
- void lookup_pointer (DIContext *context, const char **name, size_t *line, const char **filename, size_t pointer, int demangle)
167
+ void lookup_pointer (DIContext *context, const char **name, size_t *line, const char **filename, size_t pointer, int demangle, int *fromC )
168
168
{
169
+ DILineInfo info;
169
170
if (demangle && *name != NULL )
170
171
*name = jl_demangle (*name);
171
- if (context == NULL ) return ;
172
172
#ifdef LLVM35
173
173
DILineInfoSpecifier infoSpec (DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath,
174
174
DILineInfoSpecifier::FunctionNameKind::ShortName);
@@ -177,21 +177,26 @@ void lookup_pointer(DIContext *context, const char **name, size_t *line, const c
177
177
DILineInfoSpecifier::AbsoluteFilePath |
178
178
DILineInfoSpecifier::FunctionName;
179
179
#endif
180
- DILineInfo info = context->getLineInfoForAddress (pointer, infoSpec);
180
+ if (context == NULL ) goto done;
181
+ info = context->getLineInfoForAddress (pointer, infoSpec);
181
182
#ifndef LLVM35 // LLVM <= 3.4
182
- if (strcmp (info.getFunctionName (), " <invalid>" ) == 0 ) return ;
183
+ if (strcmp (info.getFunctionName (), " <invalid>" ) == 0 ) goto done ;
183
184
if (demangle)
184
- *name = jl_demangle (info.getFunctionName ());
185
+ *name = jl_demangle (info.getFunctionName ());
185
186
else
186
- *name = strdup (info.getFunctionName ());
187
+ *name = strdup (info.getFunctionName ());
187
188
*line = info.getLine ();
188
189
*filename = strdup (info.getFileName ());
189
190
#else
190
- if (strcmp (info.FunctionName .c_str (), " <invalid>" ) == 0 ) return ;
191
+ if (strcmp (info.FunctionName .c_str (), " <invalid>" ) == 0 ) goto done ;
191
192
*name = strdup (info.FunctionName .c_str ());
192
193
*line = info.Line ;
193
194
*filename = strdup (info.FileName .c_str ());
194
195
#endif
196
+ done:
197
+ // If this is a jlcall wrapper, set fromC to match JIT behavior
198
+ if (*name != NULL && memcmp (*name," jlcall_" ,7 ) == 0 )
199
+ *fromC = true ;
195
200
}
196
201
197
202
#ifdef _OS_DARWIN_
@@ -254,12 +259,12 @@ bool jl_is_sysimg(const char *path)
254
259
}
255
260
256
261
#if defined(_OS_WINDOWS_) && !defined(USE_MCJIT)
257
- void jl_getDylibFunctionInfo (const char **name, size_t *line, const char **filename, size_t pointer, int skipC)
262
+ void jl_getDylibFunctionInfo (const char **name, size_t *line, const char **filename, size_t pointer, int *fromC, int skipC)
258
263
{
259
264
return ;
260
265
}
261
266
#else
262
- void jl_getDylibFunctionInfo (const char **name, size_t *line, const char **filename, size_t pointer, int skipC)
267
+ void jl_getDylibFunctionInfo (const char **name, size_t *line, const char **filename, size_t pointer, int *fromC, int skipC)
263
268
{
264
269
#ifdef _OS_WINDOWS_
265
270
DWORD fbase = SymGetModuleBase64 (GetCurrentProcess (),(DWORD)pointer);
@@ -269,7 +274,8 @@ void jl_getDylibFunctionInfo(const char **name, size_t *line, const char **filen
269
274
Dl_info dlinfo;
270
275
const char *fname = 0 ;
271
276
if ((dladdr ((void *)pointer, &dlinfo) != 0 ) && dlinfo.dli_fname ) {
272
- if (skipC && !jl_is_sysimg (dlinfo.dli_fname ))
277
+ *fromC = !jl_is_sysimg (dlinfo.dli_fname );
278
+ if (skipC && *fromC)
273
279
return ;
274
280
// In case we fail with the debug info lookup, we at least still
275
281
// have the function name, even if we don't have line numbers
@@ -288,7 +294,9 @@ void jl_getDylibFunctionInfo(const char **name, size_t *line, const char **filen
288
294
ModuleInfo.SizeOfStruct = sizeof (IMAGEHLP_MODULE64);
289
295
SymGetModuleInfo64 (GetCurrentProcess (), (DWORD64)pointer, &ModuleInfo);
290
296
fname = ModuleInfo.LoadedImageName ;
291
- JL_PRINTF (JL_STDOUT,fname);
297
+ *fromC = !jl_is_sysimg (fname);
298
+ if (skipC && *fromC)
299
+ return ;
292
300
#endif
293
301
if (it == objfilemap.end ()) {
294
302
#ifdef _OS_DARWIN_
@@ -310,7 +318,7 @@ void jl_getDylibFunctionInfo(const char **name, size_t *line, const char **filen
310
318
if (!origerrorobj) {
311
319
objfileentry_t entry = {obj,context,slide};
312
320
objfilemap[fbase] = entry;
313
- return ;
321
+ goto lookup ;
314
322
}
315
323
#ifdef LLVM36
316
324
llvm::object::MachOObjectFile *morigobj = (llvm::object::MachOObjectFile *)origerrorobj.get ().release ();
@@ -322,7 +330,7 @@ void jl_getDylibFunctionInfo(const char **name, size_t *line, const char **filen
322
330
if (!getObjUUID (morigobj,uuid)) {
323
331
objfileentry_t entry = {obj,context,slide};
324
332
objfilemap[fbase] = entry;
325
- return ;
333
+ goto lookup ;
326
334
}
327
335
328
336
// On OS X debug symbols are not contained in the dynamic library and that's why
@@ -399,51 +407,61 @@ void jl_getDylibFunctionInfo(const char **name, size_t *line, const char **filen
399
407
context = it->second .ctx ;
400
408
slide = it->second .slide ;
401
409
}
402
- lookup_pointer (context, name, line, filename, pointer+slide, jl_is_sysimg (fname));
410
+ lookup:
411
+ lookup_pointer (context, name, line, filename, pointer+slide, jl_is_sysimg (fname), fromC);
412
+ return ;
403
413
}
414
+ *fromC = 1 ;
404
415
return ;
405
416
}
406
417
#endif
407
418
408
- void jl_getFunctionInfo (const char **name, size_t *line, const char **filename, size_t pointer, int skipC)
419
+ void jl_getFunctionInfo (const char **name, size_t *line, const char **filename, size_t pointer, int *fromC, int skipC)
409
420
{
410
421
*name = NULL ;
411
422
*line = -1 ;
412
423
*filename = " no file" ;
424
+ *fromC = 0 ;
413
425
414
426
#if USE_MCJIT
415
427
// With MCJIT we can get function information directly from the ObjectFile
416
428
std::map<size_t , ObjectInfo, revcomp> &objmap = jl_jit_events->getObjectMap ();
417
429
std::map<size_t , ObjectInfo, revcomp>::iterator it = objmap.lower_bound (pointer);
418
430
419
431
if (it == objmap.end ())
420
- return jl_getDylibFunctionInfo (name,line,filename,pointer,skipC);
432
+ return jl_getDylibFunctionInfo (name,line,filename,pointer,fromC, skipC);
421
433
if ((pointer - it->first ) > it->second .size )
422
- return jl_getDylibFunctionInfo (name,line,filename,pointer,skipC);
434
+ return jl_getDylibFunctionInfo (name,line,filename,pointer,fromC, skipC);
423
435
424
436
#ifdef LLVM36
425
437
DIContext *context = DIContext::getDWARFContext (*it->second .object );
426
438
#else
427
439
DIContext *context = DIContext::getDWARFContext (it->second .object );
428
440
#endif
429
- lookup_pointer (context, name, line, filename, pointer, 1 );
441
+ lookup_pointer (context, name, line, filename, pointer, 1 , fromC );
430
442
431
443
#else // !USE_MCJIT
432
444
433
445
// Without MCJIT we use the FuncInfo structure containing address maps
434
446
std::map<size_t , FuncInfo, revcomp> &info = jl_jit_events->getMap ();
435
447
std::map<size_t , FuncInfo, revcomp>::iterator it = info.lower_bound (pointer);
436
448
if (it != info.end () && (size_t )(*it).first + (*it).second .lengthAdr >= pointer) {
437
- // We do this to hide the jlcall wrappers when getting julia, but
438
- // it is still good to have them for regular lookup of C frames.
439
- if (skipC && (*it).second .lines .empty ())
449
+ // We do this to hide the jlcall wrappers when getting julia backtraces,
450
+ // but it is still good to have them for regular lookup of C frames.
451
+ if (skipC && (*it).second .lines .empty ()) {
452
+ // Technically not true, but we don't want them
453
+ // in julia backtraces, so close enough
454
+ *fromC = 1 ;
440
455
return ;
456
+ }
441
457
442
458
*name = (*it).second .name .c_str ();
443
459
*filename = (*it).second .filename .c_str ();
444
460
445
- if ((*it).second .lines .empty ())
461
+ if ((*it).second .lines .empty ()) {
462
+ *fromC = 1 ;
446
463
return ;
464
+ }
447
465
448
466
std::vector<JITEvent_EmittedFunctionDetails::LineStart>::iterator vit =
449
467
(*it).second .lines .begin ();
@@ -473,7 +491,7 @@ void jl_getFunctionInfo(const char **name, size_t *line, const char **filename,
473
491
}
474
492
}
475
493
else {
476
- jl_getDylibFunctionInfo (name,line,filename,pointer,skipC);
494
+ jl_getDylibFunctionInfo (name,line,filename,pointer,fromC, skipC);
477
495
}
478
496
#endif // USE_MCJIT
479
497
}
0 commit comments