Replies: 6 comments 1 reply
-
I think you either have to mark the entire region as volatile in the memory map (Windows > Memory Map), or untick "Eliminate unreachable code" (Right click in the decompiler text > Properties > Decompiler > Analysis). I think you can also change whatever type INT_STATUS is, to volatile. |
Beta Was this translation helpful? Give feedback.
-
Marking all memory regions as volatile doesn't change the output at all; unticking "Eliminate unreachable code" does make it a little better, but it still generates loops that look like |
Beta Was this translation helpful? Give feedback.
-
I can confirm that "Eliminate unreachable code" had no effect. Similarly, marking the entire region as volatile hamstrings the decompiler. Ideally, volatile could be included as part of the type. |
Beta Was this translation helpful? Give feedback.
-
This problem is common in embedded applications (ie non-os) like on the AVR and ARM Cortex M architecture. An example which occurs frequently is something like:
|
Beta Was this translation helpful? Give feedback.
-
Found a similar condition in PSX code (MIPS processor):
The decompiled code is:
Where I believe the code should be more along the lines of:
I've got the whole block ("hardware_registers" 1f801000-1f802fff) set to volatile. |
Beta Was this translation helpful? Give feedback.
-
For my particular usecase involving embedded targets that update variables inside interrupts, the solution I've found to work the best is to split the memory map isolating that particular variable and marking that split memory map as volatile. This emulates the support of volatile types the best but is a very tedious process. I would love to see volatile type support. Is there any reason for this to not be a proposal of improvement? |
Beta Was this translation helpful? Give feedback.
-
I have a function which, simplified, is as follows:
However, Ghidra doesn't know that
INT_STATUS
can change externally and instead decompiles it to an infinite loop (and kills everything after it). Is there a way to mark a structure field as volatile so that the reads don't get optimized away?Beta Was this translation helpful? Give feedback.
All reactions