- I have used Lua before, and debugging is very painful. Of course, there are already mature debuggers, such as decoda.
- How can I debug it before the debugger is available?
- Printf is printed to an output window such as the console. If hot updates are made, you can change and view them.
- Enter the command to display the result on the console. for C ++, the console is a very unpleasant thing, because every instruction has to write a parsing function. the script can directly input the script statement as a command, such as csharprepl.
- Of course, the ideal situation is to be able to place breakpoints and track them in a single step.
- Unity uses monodevelop as the debugger. Fortunately, the monodevelop and unitydebugger plug-ins are both open-source, so it is easy to copy them.
- Monodevelop has two ways to start debugging:
- Execute directly, just like pressing F5 in.
- When a process is attached, the program is started first, and then the debugger is mounted. This is more practical for the script, because you can modify it to continue debugging without restarting the game.
- Mono debugging involves a debugging server. You can use a socket to connect the client to the server. if it is started from MD, MD is the debugging server. if attach mode is used, the game is the server.
- Take attach as an example:
int port = (int)(56000 + (GetCurrentProcessId() % 1000)); char options[255]; sprintf_s(options, 255, "--debugger-agent=transport=dt_socket,address=127.0.0.1:%d,server=y", port); char* args = options; mono_jit_parse_options (1, &args); mono_debug_init (MONO_DEBUG_FORMAT_MONO);
- MD can directly use the debugger plug-in of Unity. Of course, it only recognizes processes starting with "Unity:
- In addition, the debugged dll must have an MDB file, which is equivalent to a PDB file. md generates a PDB file by default, so you need to change it to the debug information of the MDB.
- After that, everything went smoothly. breakpoint, single-step tracking, and monitoring were perfect:
C # script practice (4): Reflection and serialization