The Detroit Post
Saturday, 16 October, 2021

How To Rust Debug

author
Danielle Fletcher
• Thursday, 29 October, 2020
• 9 min read

At the very beginning, I want to share my development environment for Rust. I use the Visual Studio Code for creating Rust applications.

rust basically example
(Source: www.gitpod.io)

Contents

To hear about your development environment, I want to share mine first. For simplicity and lightweight, I select the Visual Studio Code.

While programming in Rust, it gives me warnings, errors, and hints when calling functions. How we can use debugger with the Visual Studio Code.

The package brings the debugged source code to the top part of a screen. Instead of pure GDB, I can debug by watching the source.

Using VS Code to debugs isn't perfect, but it's pretty good. If I'm missing a step or the process changes please let me know.

It probably makes sense to go ahead and install the Rust extension as well. Now that your tools are installed you need to configure your VS Code launch properties.

rust language ide code debugger programming msvc debug visual windows studio neovim
(Source: www.dunebook.com)

Click Debug Add Configuration If you're on Windows then select C++ (Windows) If you're on Mac or Linux then select LLB: Custom Launch You'll have to manually change the executable name under “program”.

I've found the Rust compiler to be a little more aggressive than C++ when it comes to optimizing away “unused” variables. Sometimes I store intermediate values in variables just for the debugger.

It wasn't behaving quite like I expected, so I stepped into the debugger. Much to my surprise I was able to seamlessly step into the crate's Rust code.

But what really shocked me is I could also step right into it's underlying C++ code! All types which want to use std::FMT formatting traits require an implementation to be printable.

Automatic implementations are only provided for types such as in the std library. All types can derive (automatically create) the FMT:: Debug implementation.

rust siren electric wiki
(Source: wiki.facepunch.com)

So FMT:: Debug definitely makes this printable but sacrifices some elegance. Big open source projects are huge, such as the Servo browser in Rust.

There are almost a hundred thousand lines of code in the Servo project. To develop such a big project, knowing how to debug in a right way is very important, since you would like to find the bottleneck in a fast and efficient way.

In this article, I will teach you some tips to use GDB developing and debugging your Rust code and the Servo project. I assume you are not familiar with software developing, but you have some skills to write codes.

So when you want to know something's in the box, you might add some lines, such as: However, it requires compiling each time when you want to know another variable’s value in the program.

Besides, when your program crashes or causes memory leak, it is hard to trace the underlying problem. The simple way is not helpful enough, which means you need a more powerful tool.

spoiled human meat rust
(Source: wiki.facepunch.com)

(On Windows platform, VS debugger is also a very strong tool, but not in discussion in this article.) Basically, their commands are almost the same, so I would just introduce how to use GDB to debug the Rust and the Servo.

In other words, GDB allows you to control the program running and to get more information from the inside of the code. For example, you can stop the program at a certain line in a file, which is called a “breakpoint”.

Backtrack means to print all functions called before the breakpoint. First, I would create a simple Hello World to demonstrate how to use GDB in a Rust project.

Please follow the in “the Rust book” to create a Hello World. Make sure you can compile, run the code, and understand what Cargo are doing.

In order to show how to use GDB, I have designed a sample code. However, if it is a release build, you cannot run with GDB, since the debug information is lost.

rust light description
(Source: wiki.facepunch.com)

If you write C/C++ codes, just add the -g flag while compiling which means building as for debugging, and the executable can be read by GDB. There are many commands in GDB, but I would only introduce the most important part for you.

(You would need to enter the whole path, like mod::mod::function in a big project) Or, you can add the file path with a line number to define where to stop.

If you are wondering what the upstream functions have been called before running to this breakpoint, you can use command backtrack or BT. General speaking, there are about thirty to forty function calls before the breakpoint in a module.

To find the backtrack by reading the code is super hard, but now we can use GDB to do it. After the previous step, we have already set a breakpoint at src/main.rs:9, and there are two frames in the backtrack, which are #0 and #1.

So, frame let you enter the scope in frame #1, and then you can use print to print the value of a variable, or you can use call to call a function at that scope. The program will keep running until it meets another breakpoints or finish the execution.

sam site rust wiki rustlabs description hp 1000
(Source: wiki.facepunch.com)

You can add some other commands here, and once you have done, you can enter c to continue the process. I will not discuss some detail such as how to apply a complicated setting for GDB, so you might need to search for other advanced articles to learn more skills.

However, he gets some troubles while developing Servo recently, I think if he knows how to use GDB, it would be easier to figure out the reasons why there are some weird behaviors by the program. I’m writing this article for him and all the developers who just become one of the Servo community.

Making statements based on opinion; back them up with references or personal experience. Debug camera is a free cam view which can be used by server administrators and developers.

By default, the camera will be positioned inside the head of the player triggering the command. The controls for the debug camera are fairly straightforward and mostly mimic existing movement keys.

You can also use the command debugcamera_savetofile to save the camera state as a .cam text file, which is stored in a folder called “cam saves” in the game's root directory. Camera save points can be called on any level, server or demo file.

rust pork burnt
(Source: wiki.facepunch.com)

A separate section labelled 'files' is listed for all .cam files stored in the “cam saves” directory. Use the command debugcamera_unfreeze to unfreeze player controls whilst remaining in the debug camera view.

This also currently causes the debug camera to track the movement origin of the player. Once parented, move the mouse to orbit the camera around the entity and targeted bone.

You can also dolly the camera in/out of the targeted entity (aka move closer or further away) by using the following commands: Use shift + r to reset the offset transform and return the debug camera to its original orbit position.

The console will print out the name of the newly targeted bone which the debug camera is parented to. Use the command cam bone to manually parent the debug camera to a particular bone.

These are useful for helping frame particular compositions in your videos and images when using the debug camera. Use debugcamera_guide 2 to enable a golden ratio Fibonacci guide for the debug camera.

combiner rust root electrical
(Source: wiki.facepunch.com)

Other Articles You Might Be Interested In

01: Utica Square Real Estate Tulsa
02: Encanto Real Estate San Diego
03: Encompass Real Estate Virginia Beach
04: Encore Real Estate Dallas
05: Encore Real Estate Detroit
06: Endeavor Real Estate Austin
07: Endeavor Real Estate Austin Texas
08: Endeavor Real Estate Group Austin Texas
09: Endeavor Real Estate Group Austin Tx
10: Endeavor Real Estate Group Denver
Sources
1 businessden.com - https://businessden.com/2019/01/24/texas-developer-buys-portion-of-broadway-station-site-plans-early-2020-groundbreaking/
2 www.metrowestmh.com - https://www.metrowestmh.com/
3 simplesourcecapital.com - https://simplesourcecapital.com/7-questions-to-ask-to-form-your-vision-of-being-a-real-estate-investor/
4 www.nancybishop.com - https://www.nancybishop.com/
5 iregroup.wordpress.com - https://iregroup.wordpress.com/
6 www.lasalle.com - https://www.lasalle.com/
7 streamrealty.com - https://streamrealty.com/
8 www.forbes.com - https://www.forbes.com/sites/mikeozanian/2013/12/18/img-sold-for-2-3-billion-to-william-morris-endeavor-and-silver-lake-partners/
9 news.yahoo.com - https://news.yahoo.com/photos/space-shuttle-endeavour-slideshow.html