#GDB is giving me a giving segmentation fault here and I'm not sure why.

6 messages · Page 1 of 1 (latest)

chilly wolf
#

Segmentation fault when reading the program
counter and incrementing it by 2 (Intel 8080)

ERROR:

Program received signal SIGSEGV, Segmentation fault.
0x0000000000405411 in nextWord (c=0x494d) at memory.c:32
32        uint16_t word = readWord(c, c->pc);

THE CODE: (I added the upper portion in case it's needed).


uint8_t readByte(i8080* const c, uint16_t addr)
{
    return c->memory[addr & 0xFF];
}

uint16_t readWord(i8080* const c, uint16_t addr)
{
    return (readByte(c, addr + 1) << 8 | readByte(c, addr)); 
}

uint16_t nextWord(i8080* const c)
{
    uint16_t word = readWord(c, c->pc);
    c->pc += 2;
    return word;
}
```C
jaunty veldtBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

ancient eagle
#

Is there a chance that you pass (directly or indirectly) an uninitialized pointer to function nextWord() ?

If you know your way around the debugger then set a BP on the offending line and inspect the callstack when the program stops there.

chilly wolf
jaunty veldtBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.

chilly wolf
#

!solved