@@ -394,10 +394,16 @@ static gimli_iter_status_t print_lua_State(gimli_proc_t proc,
394394
395395 if (p .source ) {
396396 char * src = gimli_read_string (proc , (gimli_addr_t )(p .source + 1 ));
397- int line ;
397+ int line = 0 ;
398398
399- gimli_read_mem (proc , (gimli_addr_t )(p .lineinfo + pc ), & line , sizeof (line ));
400- printf ("%s:%d @ pc=%d\n" , src + 1 , line , pc );
399+ if (p .lineinfo && pc >= 0 && pc < p .sizelineinfo ) {
400+ gimli_read_mem (proc , (gimli_addr_t )(p .lineinfo + pc ), & line , sizeof (line ));
401+ }
402+ if (line > 0 ) {
403+ printf ("%s:%d @ pc=%d\n" , src + 1 , line , pc );
404+ } else {
405+ printf ("%s @ pc=%d\n" , src + 1 , pc );
406+ }
401407 free (src );
402408 } else {
403409 printf ("[VM]\n" );
@@ -406,21 +412,28 @@ static gimli_iter_status_t print_lua_State(gimli_proc_t proc,
406412 /* print out locals */
407413 for (sn = 0 , n = 0 ; n < p .sizelocvars ; n ++ ) {
408414 char * varname ;
409- int startline , endline ;
415+ int startline = 0 , endline = 0 ;
410416 TValue val ;
411417
412418 if (gimli_read_mem (proc , (gimli_addr_t )(p .locvars + n ), & lv , sizeof (lv )) != sizeof (lv )) {
413419 break ;
414420 }
415421 if (lv .startpc > pc ) {
416- /* this local is not yet valid in this frame */
417422 continue ;
418423 }
419424
420425 varname = gimli_read_string (proc , (gimli_addr_t )(((TString * )lv .varname ) + 1 ));
421- gimli_read_mem (proc , (gimli_addr_t )(p .lineinfo + lv .startpc ), & startline , sizeof (startline ));
422- gimli_read_mem (proc , (gimli_addr_t )(p .lineinfo + lv .endpc ), & endline , sizeof (endline ));
423- printf (" local %s [lines: %d - %d] " , varname , startline , endline );
426+ if (p .lineinfo ) {
427+ if (lv .startpc >= 0 && lv .startpc < p .sizelineinfo )
428+ gimli_read_mem (proc , (gimli_addr_t )(p .lineinfo + lv .startpc ), & startline , sizeof (startline ));
429+ if (lv .endpc >= 0 && lv .endpc < p .sizelineinfo )
430+ gimli_read_mem (proc , (gimli_addr_t )(p .lineinfo + lv .endpc ), & endline , sizeof (endline ));
431+ }
432+ if (startline > 0 || endline > 0 ) {
433+ printf (" local %s [lines: %d - %d] " , varname , startline , endline );
434+ } else {
435+ printf (" local %s " , varname );
436+ }
424437 free (varname );
425438
426439 /* we can read it from the stack at offset sn from the ci.base */
0 commit comments