Skip to content

Commit 449950c

Browse files
committed
update the FAQ section with a how-to enable the logging
1 parent 45a8721 commit 449950c

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

docs/FAQ.md

+70
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,76 @@ Therefore, if you still prefer the previous `paddr = vaddr` simple mapping, we h
123123

124124
In theory, `UC_TLB_VIRTUAL` will achieve better performance as it skips all MMU details, though not benchmarked.
125125

126+
## Something is wrong - I would like to dig deeper
127+
128+
Unicorn uses at several places logging by the qemu implementation.
129+
This might provide a first glance what could be wrong.
130+
131+
The logs contains optionally the filename and the line number including
132+
additional messages to indicate what is happening.
133+
However, the qemu logs are partially commented-out and incomplete, but give it a try.
134+
You might want to dig deeper - and add your own log messages where you expect or try to find the bug.
135+
136+
See the `unicorn/qemu/include/qemu/log.h` file for details.
137+
To enable logs, you must recompile Unicorn with the enabled `LOGGING_ENABLED` define.
138+
139+
Logs are written in different log levels, which might result into a very verbose logging if enabled.
140+
To control the log level information, two environment variables could be used.
141+
142+
`UNICORN_LOG_LEVEL` and `UNICORN_LOG_DETAIL_LEVEL`.
143+
144+
These environment variables are parsed into `uint32_t` values once, (due to performance reasons)
145+
so set these environment variables before you execute any line of Unicorn.
146+
Allowed are hexa-decimal, decimal and octal values, which fits into a buffer of 10 chars. (see stroul for details).
147+
148+
To define how detailed and what should be logged, use the following environment variables:
149+
150+
- `UNICORN_LOG_LEVEL`=\<32bit mask\>
151+
- The qemu bit mask what should be logged.
152+
- Use the value of `UINT32_MAX` to log everything.
153+
- If no bit is set in the mask, there will be no logging.
154+
- `UNICORN_LOG_DETAIL_LEVEL`=\<level\>
155+
- The level defines how the filename and line is constructed.
156+
- 0: no filename and no line is used.
157+
- 1: full filename including the leading path is used with line information.
158+
- 2: just the filename with line information. It might be a little confusing,
159+
as the file name can be used in several places.
160+
- If unsure or unwanted, leave this variable undefined or set it to 0.
161+
162+
As an example to set up the environment for python correctly, see the example below.
163+
164+
```python
165+
import os
166+
os.environ['UNICORN_LOG_LEVEL'] = "0xFFFFFFFF" # verbose - print anything
167+
os.environ['UNICORN_LOG_DETAIL_LEVEL'] = "1" # full filename with line info
168+
```
169+
170+
Please note that file names are statically compiled in and can reveal the paths
171+
of the file system used during compilation.
172+
173+
## My code does not do what I would expect - is this a bug?
174+
175+
Please create an github issue and provide as much details as possible.
176+
177+
- [ ] Simplified version of your script / source
178+
- Make sure that "no" external dependencies are needed.
179+
- E.g. remove additional use of capstone or CTF tools.
180+
- [ ] Used Unicorn git-hash commit
181+
- Make sure to exclude any changes of you made in unicorn.
182+
- Alternativily provide the repo link to your commit.
183+
- [ ] Detailed explaination what is expected
184+
- Try to verify if the instructions can be processed by qemu.
185+
- Dumping the registers of unicorn and qemu helps a lot.
186+
- [ ] Detailed explaination what is observed
187+
- Describe what's going on (and what you might think about it).
188+
- [ ] Output from your executed script
189+
- You might have additional log messages which could be helpful.
190+
- [ ] Output from the qemu-logs
191+
- Try to gather more informations by enabling the qemu logging.
192+
- [ ] More details
193+
- Attach more details to help reproduce the bug.
194+
- Like attaching a repo link to the CTF challenge containing the binary or source code.
195+
126196
## I'd like to make contributions, where do I start?
127197

128198
See [milestones](https://github.com/unicorn-engine/unicorn/milestones) and [coding convention](https://github.com/unicorn-engine/unicorn/wiki/Coding-Convention

0 commit comments

Comments
 (0)