Debugger

After trying on the break point implementation last week, I decided to work on interface with Sumia and Islam’s code. As pre-discussed with my supervisor, the simulator should be the back-end engine and should not have any visible interface in the Web Application.

In order to ensure things going well, I took everything work on step by step, as I thought that things will not goes well if I merged all the break point codes that I had implemented last week. Firstly, I merged on Sumia code with the simulator alone, and they worked fine. Then, I try to put the WResource that I had created last week, to process all the addresses extraction from the C code. I was really having headache as how am I going to add in my codes if I am not allowed to add my function to Sumia or Islam’s code. After some discussion with them, they suggested me to create my own Simulator Widget which has no visible interface but just to run the code. Fortunately, this really solved the problem. After creating the widgets, I had created JavaScript function that will calls all my code, and Sumia’s code will just need to add this single function and it will take care of all the functionality.

This solved the merging of my code and Sumia and Islam code. However, more and more challenging things are coming forward. The first one would be the usage of temporary files, I did not process all my code extractions on the temporary folder but in the local folder. Thus, I have to change the code so that they are able to store the files in the temporary files, using the boost file system library. The second challenge will be the option of using JavaScript file and JSON file to store the address. The usage of JavaScript file is not suitable in this debugger implementation as I would need to pass the directory location to the web worker, so that the web worker can locate the file and process it. Thus, I had to rewrite the code to store into JSON file so that the JSON object can be passed to the web worker later using postMessage function.

The Web Worker

As pre-discussed previously, web worker does not share the variables with the JavaScript on the client as it is an asynchronous process that run on background. This comes into a challenge during the implementation of Step In debugger, as I need to pass the trigger of the step in function from JavaScript to the web worker. I found out that the web worker does not stop if it is running something in process. In another word, the web worker cannot be interrupted if it is running. However, one great thing that I found out with web worker was, the global variable or object will not be reset if the web worker is not terminated. Thus, I can send instructions by using postMessage to trigger the web worker to run other algorithm, with the previous data that is still saved. These data can be reset if we create a new web worker or terminate them using the terminate().

The Prediction Algorithm

The Step In debugger is a prediction algorithm, as it is implemented using the starting and ending address that obtained from the GDB (GNU Project Debugger). By using the addresses, I am creating an algorithm to predict whether the instructions of each line of the C code is executed and they should be stopped once they detected the it is reaching the next line or any other lines in the C program. And it should be stopped until the user triggers another step in function. I think this algorithm should be working and fine with any programs as each address will be storing different instructions, and these instructions are derived from each line of the C program.

The creation of step in function is tricky, as the user would be implementing different C code such as while loop, for loop, goto, if loop, switch function and normal functions. The step in debugger allows user to know how the C code going through, that their code actually jumps from which line to which line. Thus, the prediction algorithm should be able to adapt any C code that has been written on. I tried out the implementation from simple C program without any function, to the C programs with complicated code such as loops and functions. By using the web worker global variable and objects, I had created a step in function. The step in function compares the starting address of each C code, which derived from the GDB, And it compares with every starting address so that it can recognize the loops and function that would be located in some other lines in the file. Every time the prediction completes, it would send the line number that it is pointing to, back to the JavaScript, so that the user can visualize the line number that is going to be executed next when they trigger the “step in” function again.

The Undefined Error 0

I was horrified by the error when I saw it again. It is the execution of instruction from address 0. This error appears again when I tried out the simulator on C++ executable file. I found out that I did a mistake last week, that I manually added the stack pointer initialization instruction without adjusting the program counter back to the original entry address. Thus, the program counter actually skipped the first entry address, and eventually this is able to run all the instruction in the main section. However, this does not happen when I initialize the stack pointer and adjust back the program counter, both C/C++ executable file does not work. As per discussed by the RISC-V author themselves, the executable files are expected to be running in an OS kernel. Hopefully that I would able to solve this problem this week 🙂


0 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.