[NSWI004] Adding print prevents exception 5

Petr Tůma petr.tuma at d3s.mff.cuni.cz
Sun Jan 5 21:42:21 CET 2020


Hi,

what you describe usually happens when your data structures are corrupt - depending on exact location of things, you may or may not hit a wrong address, and when you update your code and locations change, the exact place where the exception occurs can also move.

I would probably try to look at the addresses in thread and as, and at the address that causes the exception, perhaps that would help. We can also take a look, but please commit the code and provide us with exact commit hash and exact steps to reproduce the problem.

By the way, writing code such as ++p->q->r is quite dangerous, few people know C operator precedence and associativity rules well enough to read this with any certainty. Writing ++(p->q->r) is more readable.

Petr


On 04/01/2020 21:15, Tomáš Drozdík wrote:
> Hi,
> 
> I've encountered an interesting problem that I cannot really reason about.
> 
> As I was dealing with counting references to an address space my code
> suddenly started throwing Exception 5. Via debug prints I was able to
> track down when this exception is thrown. What came as a surprise is
> that if a place a print right before this instruction everything works
> properly (i.e. tests which should pass pass). Moving this print
> anywhere else ruins it and exception is thrown.
> 
> This is a little snippet from thread_create function:
> ```
> printk("REMOVE THIS PRINT AND EXCEPTION 5 IS THROWN\n");
> ++thread->as->reference_counter;
> ```
> I've looked up that Exception 5 is an store to illegal address. What
> does it have to do with print is beyond me, obviously adding print
> does shift code in the memory and so it may get aligned or something.
> But alignment of code is compilers job. Therefore illegal address
> should be in memory, possibly in as_t structure but that contains just
> 4 integers.
> I don't know how much code I can paste here and even if I could I'm
> not even remotely aware of what can cause such behavior.
> 
> Link to repo: https://gitlab.mff.cuni.cz/teaching/nswi004/winter-2019-20/team-i_cant_c/tree/as5
> Commit hash: 80761a068cd7f342d42e7786eaf5611419ac0487
> 
> Any help would be really appreciated.
> Thanks in advance.
> 
> Sincerly
> Tomáš Drozdík
> _______________________________________________
> NSWI004 mailing list
> NSWI004 at d3s.mff.cuni.cz
> https://d3s.mff.cuni.cz/mailman/listinfo/nswi004
> 


More information about the NSWI004 mailing list