Skip to content

How to debug Nelua programs? #251

Answered by edubart
acodervic asked this question in Q&A
Discussion options

You must be logged in to vote

Using --sanitize

For quick fixes, you can use --sanitize to debug most memory corruption errors and also have a backtrace of aborts and crashes.

For example, given the following test.nelua buggy program:

local a: [4]integer

local function foo(i: integer, x: integer)
  a[i] = i
end

foo(-1, 2)
print 'finished!'

Lets run it:

$ nelua test.nelua 
array index: position out of bounds
Aborted (SIGABRT)

It aborted because of out of bounds error, but where it happened? Let's debug with --sanitize:

$ nelua --sanitize test.nelua 
array index: position out of bounds
/home/bart/.cache/nelua/test.c:164:3: runtime error: execution reached an unreachable program point
    #0 0x5d6b38f8427c in nelua_abort

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by edubart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
3 participants
Converted from issue

This discussion was converted from issue #250 on February 12, 2024 11:17.