Search code examples
rustgdb

How to extract field value from eflags in GDB


In gdb x86_64 environment, like below example, when I tried to extract field value of $eflags to use as a breakpoint condition element, I got an error.

(gdb) cond 1 ($eflags & 0x200) != 0
(gdb) continue
Continuing.
Error in testing breakpoint condition:
Invalid cast.
[Switching to Thread 1.1]

Ofcourse, when extracting a specific field of $eflags, like p $eflags & 0x200, I got also Invalid cast error.

How to get a specific field from $eflags?

I do not know whether it is related or not, I debug a Rust program.

Environment

  • uname -a: Linux ubuntuMac 5.15.0-56-generic #62-Ubuntu SMP Tue Nov 22 19:54:14 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
  • Ubuntu version: 22.04 LTS
  • cpu: Intel(R) Core(TM) i5-5250U CPU @ 1.60GHz
  • gdb version: GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1

Thanks.


Solution

  • p $eflags & 0x200

    This doesn't work because:

    (gdb) ptype $eflags
    type = flag i386_eflags {
        bool CF @0;
        bool @1;
        bool PF @2;
        bool AF @4;
        bool ZF @6;
        bool SF @7;
        bool TF @8;
        bool IF @9;
        bool DF @10;
        bool OF @11;
        bool NT @14;
        bool RF @16;
        bool VM @17;
        bool AC @18;
        bool VIF @19;
        bool VIP @20;
        bool ID @21;
    }
    

    However, you can cast $eflags to int:

    (gdb) p $eflags
    $1 = [ IF ]
    (gdb) p/x (int)$eflags
    $2 = 0x202
    (gdb) p/x (int)$eflags & 0x2
    $3 = 0x2