Author Topic: Need help displaying data in assembly language  (Read 6598 times)

Offline Ray Seyfarth

  • Single posting newcomer
  • *
  • Posts: 7
Need help displaying data in assembly language
« on: December 06, 2011, 09:17:48 pm »
I have selected Code::Blocks as the IDE for my C++ classes for this coming semester.  It is quite ready for use for C++.  I would like to select it for my assembly class (next fall), but it needs one feature.  I will be using the yasm assembler which I have working well within CB, but there is a lack of support for inspection of data in memory.  I would like a tool which would allow me to display one of more memory locations based on a hexadecimal address.  The watch facility seems somewhat close to what I would like.  I need to have a mechanism for entering an address for a variable or an array along with the basic data type for the variable.  Adding a watch is nice for C++ where the assembler knows the type of variables.  Unfortunately no such data is available from yasm.

I have downloaded the code, but hope that someone more familiar with CB will tell me how to do this task with the code as is, or suggest a reasonable way to add the required functionality.

Thanks

Ray Seyfarth

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Need help displaying data in assembly language
« Reply #1 on: December 06, 2011, 09:24:28 pm »
Have you tried the examine memory window?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Ray Seyfarth

  • Single posting newcomer
  • *
  • Posts: 7
Re: Need help displaying data in assembly language
« Reply #2 on: December 06, 2011, 10:11:26 pm »
Have you tried the examine memory window?

Yes, I have.  This provides for 1 dump of memory data and only as bytes.  I would like to have multiple regions with types like byte, short, int, long, float, double, and C strings.  Also the dump is restricted to a handful of various power of 2 sizes.  Ideally each of the regions would also have a label so that I could identify the purpose of the variable or array.

Thanks

Ray

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Need help displaying data in assembly language
« Reply #3 on: December 06, 2011, 10:27:04 pm »
Is this thing possible with command line gdb?
If it is not we can't add support for it in C::B.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Ray Seyfarth

  • Single posting newcomer
  • *
  • Posts: 7
Re: Need help displaying data in assembly language
« Reply #4 on: December 06, 2011, 10:42:28 pm »
Is this thing possible with command line gdb?
If it is not we can't add support for it in C::B.

How about "x/4xg 0x7fffffffe5b0"?  This prints 4 64 bit integers in hexadecimal.

Or "x/10fw 0x602010"?  This prints 10 4 byte floating point values.

I've done quite a bunch of these commands in gdb in the past month or two teaching assembly language.

Ray
« Last Edit: December 06, 2011, 10:55:33 pm by seyfarth »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Need help displaying data in assembly language
« Reply #5 on: December 06, 2011, 10:48:21 pm »
OK, this is the command used by the examine memory feature.
But what about the labels and other stuff you mention?

Edit:
I would be happy if you give me an example file, which can be compiled with gcc or something easily available on linux,
and all the commands you want to be able to automate using an IDE like C::B.
« Last Edit: December 06, 2011, 10:54:49 pm by oBFusCATed »
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Ray Seyfarth

  • Single posting newcomer
  • *
  • Posts: 7
Re: Need help displaying data in assembly language
« Reply #6 on: December 06, 2011, 11:12:30 pm »
OK, this is the command used by the examine memory feature.
But what about the labels and other stuff you mention?

Edit:
I would be happy if you give me an example file, which can be compiled with gcc or something easily available on linux,
and all the commands you want to be able to automate using an IDE like C::B.

I would envision a form which lets me provide the label, address, type, and count.  It would be outstanding if such a collection could hang around throughout the session or even between sessions.  Allocated memory tends to have the same addresses, so retained watches (or displays) would work pretty well.  If I am permitted to dream big, it would also be nice to be able to dump memory from a register as an address.  This would help with local variables which are on the stack.

My only purpose is in teaching assembly language.  Ultimately it would be nice to extend nasm with the equivalent to C declarations for parameters and local variables for functions.  This would probably require more work and the simplicity of just having a labelled and typed memory dump would be quite an improvement over teaching students to use the examine command.  Plus the examine command had to be re-entered.  I've experimented with gdbtui and cgdb, but CB is pretty close.  I could probably figure out how to adapt CB myself, though I expect that someone else is already prepared to adapt CB and could do it at least 10 times as fast as I would.

I can provide some code if really needed, but the functionality is essentially the examine command implemented in a GUI with data refreshed each time the debugger is ready for a new command.  I have been doing assembly coding, so I can provide an assembly example.  I could provide a C example but the feature is basically not needed in C since the type information is provided by the compiler.

Are you interested in a program which reads the degree of a polynomial, reads the coefficients, reads two numbers, a and b, allocates arrays for the polynomial, its derivative and its integral and computes some polynomial values?  This is the most interesting example which would benefit greatly from being able to display the 3 allocated arrays while the code reads and operates on the arrays.

Thanks for your interest.  It's beginning to sound like I won't have to study the CB code ;-)

Ray

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Need help displaying data in assembly language
« Reply #7 on: December 06, 2011, 11:53:24 pm »
I have some interest to improve the examine memory window (it won't happen now, but I'll add it to my todo).

So, a C example with all the possible commands will be useful.
Sometimes the examine memory window is needed even, when coding in C/C++.
An example is packing data in a buffer to be saved in a file or send on the network.

I doubt, I'll invest any time in implementing the labeling stuff.
Because no one is doing active development in asm these days.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Ray Seyfarth

  • Single posting newcomer
  • *
  • Posts: 7
Re: Need help displaying data in assembly language
« Reply #8 on: December 07, 2011, 04:55:57 pm »
I have some interest to improve the examine memory window (it won't happen now, but I'll add it to my todo).

So, a C example with all the possible commands will be useful.
Sometimes the examine memory window is needed even, when coding in C/C++.
An example is packing data in a buffer to be saved in a file or send on the network.

I doubt, I'll invest any time in implementing the labeling stuff.
Because no one is doing active development in asm these days.

Even in C/C++ it can be handy to give names to areas of memory.  This is more critical if there is more than 1 such area.  I can imagine that there might be cases when you might not have a local or global variable giving convenient access to an array of data.  The data could be accessible through a moderate amount of indirection and giving convenient access would be nice.  It would also be nice to allow naming these arrays or variables in case someone needs to track multiple variables.  It should be a minor matter to add names to the new capability if done at the time it is created.

On another note I noticed some python code within the CB source code and discovered that the latest versions of gdb support python coding.  I am a little rusty on python, but I am preparing a define-variable and print-variable pair of commands to allow the user to develop a crude symbol table.  So far I am somewhat successful with reviving some python skills and have the commands saving variable data in a python dictionary.  I can see that I need to do some parameter checking next to force reasonable data for the dictionary data.  This will work well for my uses within gdb.

I have written an assembly book which I hope to update by next fall with better debugging capabilities.  It would be nice to include CB as an IDE for developing yasm code in the book for next fall's class.  Students had some difficulties coping well with gdb.  I am sure I can at least minimize the pain of using gdb directly, though I hope I can get CB up to speed.

I agree with you assessment that few people develop in assembly.  There are only a few who do this for high efficiency.  The purpose for my class is simply for the students to get a firmer grasp on what C/C++ does with high level code.  I don't think any of my students is likely to write any code which is more efficient that g++.  It is hard to beat g++.

Thanks again for your interest.

Ray

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Need help displaying data in assembly language
« Reply #9 on: December 07, 2011, 05:36:00 pm »
Even in C/C++ it can be handy to give names to areas of memory.  This is more critical if there is more than 1 such area.  I can imagine that there might be cases when you might not have a local or global variable giving convenient access to an array of data.  The data could be accessible through a moderate amount of indirection and giving convenient access would be nice.  It would also be nice to allow naming these arrays or variables in case someone needs to track multiple variables.  It should be a minor matter to add names to the new capability if done at the time it is created.
I don't understand how this is related to C/C++.
Still waiting for the c/c++ and gdb commands, btw.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Ray Seyfarth

  • Single posting newcomer
  • *
  • Posts: 7
Re: Need help displaying data in assembly language
« Reply #10 on: December 07, 2011, 08:02:07 pm »
Even in C/C++ it can be handy to give names to areas of memory.  This is more critical if there is more than 1 such area.  I can imagine that there might be cases when you might not have a local or global variable giving convenient access to an array of data.  The data could be accessible through a moderate amount of indirection and giving convenient access would be nice.  It would also be nice to allow naming these arrays or variables in case someone needs to track multiple variables.  It should be a minor matter to add names to the new capability if done at the time it is created.
I don't understand how this is related to C/C++.
Still waiting for the c/c++ and gdb commands, btw.

Here is a sample C++ program:

#include <iostream>

using namespace std;

class Data
{
    public:
        double *x;
        double *y;
        int n;
};

main()
{
    Data data;
    int i;

    data.n = 10;

    data.x = new double[10];
    data.y = new double[10];

    for ( i = 0;  i < data.n; i++ ) {
        cin  >>  data.x  >>  data.y;
    }

    return 0;
}

Here's a fragment from a gdb session:

(gdb) b main
Breakpoint 1 at 0x4006fd: file cpptest.cpp, line 18.
(gdb) r
Starting program: /home/seyfarth/cpptest/a.out

Breakpoint 1, main () at cpptest.cpp:18
18          data.n = 10;
(gdb) n
20          data.x = new double[10];
(gdb)
21          data.y = new double[10];
(gdb)
23          for ( i = 0;  i < data.n; i++ ) {
(gdb) n
24              cin  >>  data.x  >>  data.y;
(gdb) n
1 5
23          for ( i = 0;  i < data.n; i++ ) {
(gdb) p/x data.x
$1 = 0x602010
(gdb) p/x data.y
$2 = 0x602030
(gdb) x/4fg 0x602010
0x602010:       1       0
0x602020:       0       1.6304166312761136e-322
(gdb) x/4fg 0x602030
0x602030:       5       0
0x602040:       0       4.001931731314097e-322
(gdb)

In this program the data is doubles so the examine command needs "fg" after the number of items to dump.  For general use there needs to be a way to specify the number of items, the format and the size.

This program is very simple, but there are 2 arrays.  It would also be possible to use "x/4fg data.x".  As things get more complicated the expression to get to the address could be confusing.  With 2 arrays it would be nice to allow a label for the arrays to clarify the intent.

Thanks

Ray
« Last Edit: December 10, 2011, 12:40:12 am by Ray Seyfarth »

zabzonk

  • Guest
Re: Need help displaying data in assembly language
« Reply #11 on: December 07, 2011, 08:55:17 pm »
Possibly you meant this, but maybe you are not aware that:

     data.x = new double(10);

does not dynamically allocate an array of 10 elements - it allocates a single double and initialises it to the value 10.

Offline Ray Seyfarth

  • Single posting newcomer
  • *
  • Posts: 7
Re: Need help displaying data in assembly language
« Reply #12 on: December 07, 2011, 11:31:39 pm »
Possibly you meant this, but maybe you are not aware that:

     data.x = new double(10);

does not dynamically allocate an array of 10 elements - it allocates a single double and initialises it to the value 10.

Hi Neil!

Thanks for the correction.  I wrote this quickly to show how a more sophisticated memory dump could be useful and should have used [].  I have modified the original post in case this gets used.

Ray
« Last Edit: December 08, 2011, 12:59:25 am by Ray Seyfarth »