Hey coders, ever wonder why your program’s acting funky? Join me to master debugging with xxd! This vid walks you through inspecting text or binary file output at the byte level, catching sneaky characters like null bytes that mess up automation or school assignments. From assembly to redirects, learn practical tips to ensure clean output. Perfect for beginners and pros alike! Hit subscribe for more coding tutorials, and check my site for extra goodies. Let’s debug smarter, not harder!
Introduction to xxd 00:00:00
Purpose of debugging 00:00:12
Why debug output 00:00:23
Example assembly program 00:00:56
Running the program 00:01:26
Corrupting the message 00:01:45
Terminal vs automation 00:02:27
Installing xxd 00:03:16
Redirecting output 00:03:29
Using xxd to debug 00:04:33
Identifying newline issue 00:05:36
Finding zero in string 00:06:04
Debugging conclusion 00:06:32
Weird symbols warning 00:06:47
Debugging standard error 00:07:23
Closing remarks 00:07:40
Call to subscribe 00:07:56
QR code and website 00:08:45
Request for comments 00:09:09
Fade out 00:09:31
Thanks for watching!
Find us on other social media here:
- https://www.NeuralLantern.com/social
Please help support us!
- Subscribing + Sharing on Social Media
- Leaving a comment or suggestion
- Subscribing to our Blog
- Watching the main “pinned” video of this channel for offers and extras
Hey there, I’d like to talk to you about debugging your program’s output with xxd.
What am I talking about? Well, there’s a program called xxd that can sort of inspect
at the byte level the output of some text file or binary file. It’s really useful for
inspecting things. Why would you want to debug the output of your program? Well, I don’t know.
print a message from your program the program might be printing some extra characters somewhere
or some garbage and maybe maybe you don’t notice because you’re sort of looking at your program’s
output in the terminal but then maybe if your output is being sent to another program
for the purposes of automation or like you’re getting a grade from a class or something like
that then um well it can it can sort of it can sort of get you without you realizing what’s wrong
you an example real fast of what i’m talking about i have a simple assembly program here this is not
a video about how to write assembly code so just assume that you know if you want to know assembly
see my other videos but um i’m just going to print a simple message i’m just going to print
hello i feel awesome and then the length of the message i’m specifying here you don’t know you
don’t need to know too much about this for this particular video i’m just printing a string in
assembly that’s all i’m doing and then here you can see i’m just kind of like printing it and then
I’m just kind of like printing it and then I’m like exiting.
So if we go back to the terminal here, I can type make run.
This is not a make file video.
See my other videos.
I want to type make run just to compile and run the program.
And then here’s the message that it prints, right?
Hello, I feel awesome.
It looks good in the terminal.
I can’t be 100% sure though, because think about this.
What if I corrupted the message on purpose?
This can happen in assembly all the time.
Wrong or if you add extra characters at the end of it or even if you have you know a corrupted register somewhere
That either reads from the wrong spot
To get a string or maybe it it writes over the string for some reason. There’s a lot of things that can go wrong
So for now just suppose that I’ve corrupted my message somehow by I don’t know. Let’s put a zero
In between the string so I’m gonna say is that it’s gonna be like H E L
0 L O and what that should do is
lo and what that should do uh well it should look like just the word hello but if i’m automating
this program or sending it in to get a grade at a school somewhere then this should you know not
match what is expected if i’m automating with like another system in some way but it should look okay
in the terminal let’s see i’m going to do clear and make run notice how the message looks the same
I feel awesome. So if I was automating, you know, if I was sending this string to another program
for automation, I might be convinced that I’m not doing anything wrong. And I’ll, I’ll think it’s
the other side that is wrong or, or our computers are just buggy or something like that. But actually
I’ve outputted a corrupted message for some reason. So how can I really be sure that my
message is what I think I’m seeing in the terminal? That’s the XXD program. Pretty easy.
apt install xxd let me see if I have it on this system oh it’s already installed
okay good so I’m gonna do clear and make run again so there it is I would like to
just redirect the standard output pipe to a file with a special command in the
shell let me just show you real fast I am definitely printing to std out the
standard pipe which is just a number one file descriptor if you don’t understand
If you don’t understand that, I have other videos, but I’m going to run the program again,
but then I’m going to redirect the output to a file and I’m going to call it stdout.txt.
It’s probably a good idea to eliminate spaces.
I think I’ve made mistakes in other videos where I didn’t put a space before or after
this little redirector symbol and I ended up creating a file just called the number
two or the number one.
But pipe number one is standard output.
So I’m going to say anything that comes to pipe one, which is standard output, I’m just
output I’m just going to redirect it to a text file. So when I hit enter notice
how nothing prints to the screen but the standard output text file that I
specified is now created. If I spill the contents of std out it still looks
normal so don’t let that trick you but watch what happens if I use xxd.
xxd std out basically xxd is going to read it as a binary file and tell me
every single character in there while I oh I forgot to change the title of that
that’s not this video but notice right here where it says H E L L O and then
right before that there’s like a little dot if you look at the dot let’s see
what is the dot it’s one two three four five six it’s the sixth thing one two
one two three four five six seven eight nine ten twelve thirteen fourteen fifteen oh there’s
fifteen characters but there’s not that many i think probably they’re packing them by two here
let me see if that makes more sense now one two three four five six one two three four five six
yeah that makes a lot more sense so the sixth uh byte not the sixth uh word uh is basically
to this dot right here and if you recall oa is a decimal 10 which is uh the beginning of a new line
you know like a carriage return line feed um 13 comma 10 so that’s what it is right there
and then so now we know that there’s xxd is figuring out here or helping us understand
that there’s a new line between slash main and then the message which if you recall that’s
exactly what happened and then when we look into our hello string there’s a dot in the middle here
string there’s a dot in the middle here what is that dot well we just have to figure out what
number that corresponds to so the oa was that dot right there so we just got to go a couple more
bytes forward one two three four bytes forward one two three four bytes forward it’s this zero right
so xxd even though the terminal didn’t help us originally xxd has helped us realize that we’re
that we’re actually printing a zero under the hood and we can’t see it in the terminal.
So we have now debugged our output. You know, depending on where you print this,
you might see nothing like in the terminal. It didn’t really show anything. But if you’re on a
webpage somewhere or some other type of thing that’s going to print the data for you, you might
see a weird symbol. I mean, it really depends. This is not something you’ll see everywhere, but
you might see a weird symbol that kind of looks like a black diamond with a question mark inside
mark inside of it or some other weird symbol.
If you start seeing weird symbols all over the place or just in a place where you know
there’s not supposed to be a weird symbol, that might be an indication to you that you
have weird values sitting inside of your string.
And then you should probably try to debug with XXD.
So that’s it.
That’s the basics for debugging with XXD.
Just, you know, file output anyway, for your information.
If you wanted to debug the standard error pipe, you could also do this.
you know because the error pipe is just a two um and that’s basically it i’m not going to
debug right now because that’s that’s too easy but i hope you enjoyed this video thank you for
watching i hope you learned a little bit and had a little bit of fun i’ll see you in the next video
hey everybody thanks for watching this video again from the bottom of my heart i really
appreciate it i do hope you did learn something and have some fun uh if you could do me a please
If you could do me a please, a small little favor, could you please subscribe and follow this channel or these videos or whatever it is you do on the current social media website that you’re looking at right now.
It would really mean the world to me and it’ll help make more videos and grow this community.
So we’ll be able to do more videos, longer videos, better videos, or just I’ll be able to keep making videos in general.
So please do me a kindness and subscribe.
the middle of the night and i just wake up because i know somebody subscribed or followed
it just wakes me up and i get filled with joy that’s exactly what happens every single time
so you could do it as a nice favor to me or you could you could troll me if you want to just wake
me up in the middle of the night just subscribe and then i’ll i’ll just wake up i promise that’s
what will happen also uh if you look at the middle of the screen right now you should see a qr code
which you can scan in order to go to the website which i think is also named somewhere at the
you to my main website where you can just kind of like see all the videos I published and the
services and tutorials and things that I offer and all that good stuff and uh if you have a
suggestion for uh uh clarifications or errata or just future videos that you want to see please
leave a comment or if you just want to say hey what’s up what’s going on you know just send me
a comment whatever I also wake up for those in the middle of the night I get I wake up in a cold
it would really mean the world to me. I would really appreciate it. So again,
thank you so much for watching this video and enjoy the cool music as I fade
into the darkness, which is coming for us all.
Thank you.