Open-source News

AMD Radeon RX 7900 XTX & RX 7900 XT Arrive For Linux Testing

Phoronix - Thu, 12/08/2022 - 22:00
At the start of November AMD announced the Radeon RX 7900 series while these high-end RDNA3 graphics cards will go on sale next week. Both the Radeon RX 7900 XT and RX 7900 XTX are at Phoronix for Linux testing with AMD's fully open-source graphics driver stack while today the embargo expires on showing off the hardware.

PHP 8.2 Released With Readonly Classes, Random Extension

Phoronix - Thu, 12/08/2022 - 20:09
PHP 8.2 is out today as the annual major feature release to this widely-used scripting language primarily for web purposes...

The Most Interesting New Features For Linux 6.1

Phoronix - Thu, 12/08/2022 - 19:43
With the Linux 6.1 kernel set to be released this weekend, here is a look back at the prominent changes to find with this kernel. Linux 6.1 besides being the last kernel version of the year is all the more important in that it's expected to be the new Long Term Support (LTS) kernel...

RADV Lands Dynamic Rasterization Samples & Line Rasterization Mode

Phoronix - Thu, 12/08/2022 - 18:40
Thanks to the work led by Valve engineers on the open-source Linux graphics stack, Mesa 23.0 continues picking up new features for the Radeon Vulkan "RADV" driver...

Intel oneAPI Level Zero Being Packaged Up For Fedora

Phoronix - Thu, 12/08/2022 - 18:12
While Intel's GPU compute stack for Linux is fully open-source, one area where it still has room for improvement is getting it packaged up on more Linux distributions. The reference binaries published by Intel for their Compute-Runtime and Level Zero components are just Debian/Ubuntu packages but with time -- and as Arc Graphics and other hardware becomes available -- we are seeing more distributions taking a stab at offering up their own package builds...

10 Best PuTTY Alternatives for SSH Remote Connection

Tecmint - Thu, 12/08/2022 - 16:18
The post 10 Best PuTTY Alternatives for SSH Remote Connection first appeared on Tecmint: Linux Howtos, Tutorials & Guides .

Brief: In this tutorial, we explore 10 of the best PuTTY alternatives for SSH clients. Putty is one of the most popular and widely-used SSH and Telnet clients that allows users to log in

The post 10 Best PuTTY Alternatives for SSH Remote Connection first appeared on Tecmint: Linux Howtos, Tutorials & Guides.

7 pro tips for using the GDB step command

opensource.com - Thu, 12/08/2022 - 16:00
7 pro tips for using the GDB step command Alexandra Thu, 12/08/2022 - 03:00

A debugger is software that runs your code and examines any problems it finds. GNU Debugger (GBD) is one of the most popular debuggers, and in this article, I examine GDB's step command and related commands for several common use cases. Step is a widely used command but there are a few lesser known things about it which might be confusing. Also, there are ways to step into a function without actually using the step command itself such as using the less known advance command.

No debugging symbols

Consider a simple example program:

#include
int num() {
return 2;
}
void bar(int i)
{
printf("i = %d\n", i);
}
int main()
{
bar(num());
return 0;
}

If you compile without the debugging symbols first, set a breakpoint on bar and then try to step within it. The GDB gives an error message about no line number information:

gcc exmp.c -o exmp
gdb ./exmp
(gdb) b bar
Breakpoint 1 at 0x401135
(gdb) r
Starting program: /home/ahajkova/exmp
Breakpoint 1, 0x0000000000401135 in bar ()
(gdb) step
Single stepping until exit from function bar,
which has no line number information.
i = 2
0x0000000000401168 in main ()Stepi

It is still possible to step inside the function that has no line number information but the stepi command should be used instead. Stepi executes just one instruction at a time. When using GDB's stepi command, it's often useful to first do display/i $pc. This causes the program counter value and corresponding machine instruction to be displayed after each step:

(gdb) b bar
Breakpoint 1 at 0x401135
(gdb) r
Starting program: /home/ahajkova/exmp
Breakpoint 1, 0x0000000000401135 in bar ()
(gdb) display/i $pc
1: x/i $pc
=> 0x401135 <bar+4>: sub $0x10,%rsp

In the above display command, the i stands for machine instructions and $pc is the program counter register.

It can be useful to use info registers and print some register contents:

(gdb) info registers
rax 0x2 2
rbx 0x7fffffffdbc8 140737488346056
rcx 0x403e18 4210200
(gdb) print $rax
$1 = 2
(gdb) stepi
0x0000000000401139 in bar ()
1: x/i $pc
=> 0x401139 <bar+8>: mov %edi,-0x4(%rbp)

More Linux resources Linux commands cheat sheet Advanced Linux commands cheat sheet Free online course: RHEL technical overview Linux networking cheat sheet SELinux cheat sheet Linux common commands cheat sheet What are Linux containers? Our latest Linux articles Complicated function call

After recompiling the example program with debugging symbols you can set the breakpoint on the bar call in main using its line number and then try to step into bar again:

gcc -g exmp.c -o exmp
gdb ./exmp
(gdb) b exmp.c:14
Breakpoint 1 at 0x401157: file exmp.c, line 14.
(gdb) r
Starting program: /home/ahajkova/exmp
Breakpoint 1, main () at exmp.c:14
14 bar(num());

Now, let's step into bar():

(gdb) step
num () at exmp.c:4
4 return 2;

The arguments for a function call need to be processed before the actual function call, so num() is expected to execute before bar() is called. But how do you step into the bar as was desired? You need to use the finish command and step again:

(gdb) finish
Run till exit from #0 num () at exmp.c:4
0x0000000000401161 in main () at exmp.c:14
14 bar(num());
Value returned is $1 = 2
(gdb) step
bar (i=2) at exmp.c:9
9 printf("i = %d\n", i);Tbreak

The tbreak command sets a temporary breakpoint. It's useful for situations where you don't want to set a permanent breakpoint. For example, if you want to step into a complicated function call like f(g(h()), i(j()), ...) , in such a case you need a long sequence of step/finish/step to step into f . Setting a temporary breakpoint and then using continue can help to avoid using such sequences. To demonstrate this, you need to set the breakpoint to the bar call in main as before. Then set the temporary breakpoint on bar.  As a temporary breakpoint it is automatically removed after being hit:

(gdb) r
Starting program: /home/ahajkova/exmp
Breakpoint 1, main () at exmp.c:14
14 bar(num());
(gdb) tbreak bar
Temporary breakpoint 2 at 0x40113c: file exmp.c, line 9.

After hitting the breakpoint on the call to bar and setting a temporary breakpoint on bar, you just need to continue to end up in  bar.

(gdb) continue
Continuing.
Temporary breakpoint 2, bar (i=2) at exmp.c:9
9 printf("i = %d\n", i);Disable command

Alternatively, you could set a normal breakpoint on bar , continue, and then disable this second breakpoint when it's no longer needed. This way you can achieve the same results as with the tbreak with one extra command:

(gdb) b exmp.c:14
Breakpoint 1 at 0x401157: file exmp.c, line 14.
(gdb) r
Starting program: /home/ahajkova/exmp
Breakpoint 1, main () at exmp.c:14
14 bar(num());
(gdb) b bar
Breakpoint 2 at 0x40113c: file exmp.c, line 9.
(gdb) c
Continuing.
Breakpoint 2, bar (i=2) at exmp.c:9
9 printf("i = %d\n", i);
(gdb) disable 2

As you can see, the info breakpoints  command displays n under Enbwhich means it’s disabled but you can enable it later if it’s needed again.

(gdb) info breakpoints
Num Type Disp Enb Address What
1 breakpoint keep y 0x0000000000401157 in main at exmp.c:14
breakpoint already hit 1 time
2 breakpoint keep n 0x000000000040113c in bar at exmp.c:9
breakpoint already hit 1 time
(gdb) enable 2
(gdb) info breakpoints
Num Type Disp Enb Address What
1 breakpoint keep y 0x000000000040116a in main at exmp.c:19
breakpoint already hit 1 time
2 breakpoint keep y 0x0000000000401158 in bar at exmp.c:14
breakpoint already hit 1 timeAdvance location

Another option you can use is an advance command. Instead of tbreak bar ; continue , you can simply do advance bar . This command continues running the program up to the given location.

The other cool thing about advance is that if the location that you try to advance to is not reached, GDB will stop after the current frame's function finishes. Thus, execution of the program is constrained:

Breakpoint 1 at 0x401157: file exmp.c, line 14.
(gdb) r
Starting program: /home/ahajkova/exmp
Breakpoint 1, main () at exmp.c:14
14 bar(num());
(gdb) advance bar
bar (i=2) at exmp.c:9
9 printf("i = %d\n", i);Skipping a function

Yet another way to step into the bar, avoiding num, is using the skip command:

(gdb) b exmp.c:14
Breakpoint 1 at 0x401157: file exmp.c, line 14.
(gdb) skip num
Function num will be skipped when stepping.
(gdb) r
Starting program: /home/ahajkova/exmp
Breakpoint 1, main () at exmp.c:14
14 bar(num());
(gdb) step
bar (i=2) at exmp.c:9
9 printf("i = %d\n", i);

To know which functions are currently skipped,  info skip is used.  The num function is marked as enabled to be skipped by y:

(gdb) info skip
Num Enb Glob File RE Function
1 y n <none> n num

If skip is not needed any more it can be disabled (and re-enabled later) or deleted altogether. You can add another skip and disable the first one and then delete them all. To disable a certain skip, its number has to be specified, if not specified, each skipis disabled. It works the same for enabling or deleting a skip:

(gdb) skip bar
(gdb) skip disable 1
(gdb) info skip
Num Enb Glob File RE Function
1 n n <none> n num
2 y n <none> n bar
(gdb) skip delete
(gdb) info skip
Not skipping any files or functions.GDB step command

Using GDB's step command is a useful tool for debugging your application. There are several ways to step into even complicated functions, so give these GDB techniques a try next time you're troubleshooting your code.

There are several ways to step into even complicated functions, so give these GDB techniques a try next time you're troubleshooting your code.

Image by:

Pixabay, testbytes, CC0

Linux What to read next GNU Debugger cheat sheet This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License. Register or Login to post a comment.

Pages