Thread: prining a register?

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    52

    prining a register?

    Hi everyone,
    I have a flag defined like this:

    #define TMSK1 *(volatile char*)0x1022

    I would like to print its value but I'm not sure how to do this in GDB
    every time I try it, I get an error:

    "No symbol TMSK1 in current context."

    Ted

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Remember that #define directives are handled by the preprocessor - it's pretty much an automated search & replace that runs before the compiler. So in the text of your source file, every occurrence of the sequence "TMSK1" is literally replaced by "*(volatile char*)0x1022" before the compiler looks at the code. So really - there is no TMSK1 symbol.

    I'm not a big GDB user, so I have no idea if there's an easy way to see what's in memory at a certain location (though I'd imagine there is).

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    412
    I have never used gdb so don't shoot the messenger if this turns out to be wrong
    But a quick google search and this came up
    RMS's gdb Tutorial: Advanced gdb Features
    Use the x command to examine memory. The syntax for the x command is x/FMT ADDRESS. The FMT field is a count followed by a format letter and a size letter. There are many options here, use the help command 'help x' to see them all. The ADDRESS argument can either be a symbol name, such as a variable, or a memory address.
    so try
    x/c 0x1022

  4. #4
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Why not change it to something like:
    Code:
    volatile const char* TMSK1 = 0x1022;
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. register variables
    By BEN10 in forum C Programming
    Replies: 9
    Last Post: 04-17-2009, 07:20 AM
  2. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  3. register file
    By axon in forum Tech Board
    Replies: 0
    Last Post: 11-20-2003, 09:07 AM
  4. difference between register int and normal int
    By GanglyLamb in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 02-25-2003, 04:01 PM
  5. DOS, Serial, and Touch Screen
    By jon_nc17 in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 01-08-2003, 04:59 PM