473,327 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

debugging

Hi,

I would like to view the contents of structure as part of a debugging
routine.
The structure is represented by a pointer ptr->data.
I would like to view the first element in the array, data. This is part
of debugging this program.
A problem occured when a 2D binary array: ptr->data was copied to the
another array in another structure via memcpy(). Since the codes is
big, I will only post the relevant parts I feel is needed - I might be
wrong. Here is a summary:

******************************************
struct hdfstruct {
float** latitude;
} hdfdata;

int main(void) {

printf("Allocating memory!\n");
hdfdata.latitude = calloc(ROW,sizeof(float *));
if(hdfdata.latitude == NULL) {
fprintf(stderr, "Failed to allocate memory\n");
return EXIT_FAILURE;
}
for (i = 0; i < 15; i++) {
hdfdata.latitude[i] = calloc(15,sizeof(float));
if(hdfdata.latitude == NULL) {
fprintf(stderr, "Failed to allocate memory\n");
return EXIT_FAILURE;
}
}
/* Reading the hdf data into the arrays */
stat = readHDF(hdfdata.latitude,latfile,"/LAT");
}
int readHDF(float **arp, char *hdfname, char *fieldname) {
/* omitted the parts concerning extracting the data */
/* I didn't write it so I kow that it works */
memcpy(arp, cloudproduct->data, 15*15*4);
return (1) /* zero is returned on error */
}
*************************************
Now I don't want to sent the structure into the readhdf function as I
will be calling the function many times so it is necessary to send a
pointer instead. Still the results is that the entire 2D array has the
same value and this is wrong. The codes runs without error but an error
ocurred somewhere.
To summerize: I am wondering if there is a way to view a structure like
in python: print list and to comfirm my suspicion about the memcpy to
the pointer.

I certainly hope that I gave enough info to get some help.

Thanks in advance,
Sheldon

Oct 30 '06 #1
4 1600
Sheldon wrote:
I would like to view the contents of structure as part of a debugging
routine.
<snip>
To summerize: I am wondering if there is a way to view a structure like
in python: print list and to comfirm my suspicion about the memcpy to
the pointer.
Write a function to print the structure. eg:
void pretty_print (struct foo *f)
{
printf("a=%d\t b=%d\nc=%d\tc=%d\n", f->a, f->b, f->c, f->c);
}

Now, in your debugger, make a call to the function.

--
Bill Pursell

Oct 30 '06 #2

Bill Pursell skrev:
Sheldon wrote:
I would like to view the contents of structure as part of a debugging
routine.
<snip>
To summerize: I am wondering if there is a way to view a structure like
in python: print list and to comfirm my suspicion about the memcpy to
the pointer.

Write a function to print the structure. eg:
void pretty_print (struct foo *f)
{
printf("a=%d\t b=%d\nc=%d\tc=%d\n", f->a, f->b, f->c, f->c);
}

Now, in your debugger, make a call to the function.

--
Bill Pursell
This would work if I had simple scalars in the structure but there are
arrays and strings as well as integers/floats. I just would like to
know what are the names of the variables in the structure and perhaps
the variable types.

/Sheldon

Oct 30 '06 #3

Sheldon wrote:
Bill Pursell skrev:
Sheldon wrote:
I would like to view the contents of structure as part of a debugging
routine.
<snip>
To summerize: I am wondering if there is a way to view a structure like
in python: print list and to comfirm my suspicion about the memcpy to
the pointer.
Write a function to print the structure. eg:
void pretty_print (struct foo *f)
{
printf("a=%d\t b=%d\nc=%d\tc=%d\n", f->a, f->b, f->c, f->c);
}

Now, in your debugger, make a call to the function.
>
This would work if I had simple scalars in the structure but there are
arrays and strings as well as integers/floats. I just would like to
know what are the names of the variables in the structure and perhaps
the variable types.
This will work for anything, but the function you need to
write simply has to account for the content of the structure.
For example, you can do something like:

#include <stdio.h>
#include <stdlib.h>

struct array_list {
char *name;
int *a;
size_t size_a;
struct array_list *next;
};

void
print_array(int *a, size_t s)
{
size_t i;
for (i=0; i < s; i++)
printf("%d ", a[i]);
}

void
print_array_list (struct array_list *d)
{
struct array_list *this;
printf("%s = ", d->name);
print_array( d->a, d->size_a);
putchar('\n');
for( this = d->next; this != NULL; this = this->next)
print_array_list(this);
}

void * Malloc(size_t size)
{
void *ret;
ret = malloc(size);
if (ret == NULL)
exit (EXIT_FAILURE);
return ret;
}
int
main(void)
{
struct array_list a,b;
int i;

a.name = "struct a";
b.name = "struct b";
a.size_a = 5;
b.size_a = 3;
a.a = Malloc(a.size_a * sizeof *a.a);
b.a = Malloc(b.size_a * sizeof *b.a);
for (i=0; i < a.size_a; i++)
a.a[i] = 5 * i;
for (i=0; i < b.size_a; i++)
b.a[i] = -2 * i;
a.next = &b;
b.next = NULL;

print_array_list (&a);
return EXIT_SUCCESS;
}

This produces the output:
$ ./a.out
struct a = 0 5 10 15 20
struct b = 0 -2 -4

--
Bill Pursell

Oct 30 '06 #4

Bill Pursell skrev:
Sheldon wrote:
Bill Pursell skrev:
Sheldon wrote:
>
I would like to view the contents of structure as part of a debugging
routine.
<snip>
To summerize: I am wondering if there is a way to view a structure like
in python: print list and to comfirm my suspicion about the memcpy to
the pointer.
>
Write a function to print the structure. eg:
void pretty_print (struct foo *f)
{
printf("a=%d\t b=%d\nc=%d\tc=%d\n", f->a, f->b, f->c, f->c);
}
>
Now, in your debugger, make a call to the function.

This would work if I had simple scalars in the structure but there are
arrays and strings as well as integers/floats. I just would like to
know what are the names of the variables in the structure and perhaps
the variable types.

This will work for anything, but the function you need to
write simply has to account for the content of the structure.
For example, you can do something like:

#include <stdio.h>
#include <stdlib.h>

struct array_list {
char *name;
int *a;
size_t size_a;
struct array_list *next;
};

void
print_array(int *a, size_t s)
{
size_t i;
for (i=0; i < s; i++)
printf("%d ", a[i]);
}

void
print_array_list (struct array_list *d)
{
struct array_list *this;
printf("%s = ", d->name);
print_array( d->a, d->size_a);
putchar('\n');
for( this = d->next; this != NULL; this = this->next)
print_array_list(this);
}

void * Malloc(size_t size)
{
void *ret;
ret = malloc(size);
if (ret == NULL)
exit (EXIT_FAILURE);
return ret;
}
int
main(void)
{
struct array_list a,b;
int i;

a.name = "struct a";
b.name = "struct b";
a.size_a = 5;
b.size_a = 3;
a.a = Malloc(a.size_a * sizeof *a.a);
b.a = Malloc(b.size_a * sizeof *b.a);
for (i=0; i < a.size_a; i++)
a.a[i] = 5 * i;
for (i=0; i < b.size_a; i++)
b.a[i] = -2 * i;
a.next = &b;
b.next = NULL;

print_array_list (&a);
return EXIT_SUCCESS;
}

This produces the output:
$ ./a.out
struct a = 0 5 10 15 20
struct b = 0 -2 -4

--
Bill Pursell
You are too good, simply too good.

Thanks,
Will try this out.

Oct 30 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: ZMan | last post by:
Scenario: This is about debugging server side scripts that make calls to middle-tier business DLLs. The server side scripts are legacy ASP 3.0 pages, and the DLLs are managed DLLs...
16
by: Serdar Kalaycý | last post by:
Hi everybody, My problem seems a bit clichè but I could not work around. Well I read lots of MSDN papers and discussions, but my problem is a bit different from them. When I tried to run the...
2
by: Andy Fish | last post by:
Hi, Using VS.NET 2003, when I use 'F5' to start debugging my web app, it obviously attaches the IDE to IIS for server debugging. However, it also seems to put IE into some kind of debugging mode...
2
by: Alex Clark | last post by:
Hi All, My system: WinXP Pro, VS.NET 2003, SQL Server Personal Edition. I'm having problems with my old favourite demon, SQL Debugging from within VS.NET. I have to say I've found this...
5
by: Velvet | last post by:
Can someone tell me to what process I need to attach to be able to step through my classic ASP code in VS.net 2003. I'm working on an XP box with IIS installed. I also have VS.net 2005 (The...
6
by: KevinGPO | last post by:
I am currently developing a website in ASP (VBScript) using MS Visual C#.NET IDE. I just create a new "ASP.NET Web Application" and point to my local webserver (IIS) of my website address. Then I...
5
by: phnimx | last post by:
Hi , We have developed a number of plug-in .NET Library Components that we typically deploy with our various applications by installing them into the GAC. Each of the applications contains an...
5
by: =?Utf-8?B?Z2FkeWE=?= | last post by:
I can't get to debug on my local IIS using VStudio.net 2005 Prof. I can on the development server. I get the msg 'the server does not support debugging for asp.net...' I have done the following...
2
jwwicks
by: jwwicks | last post by:
C/C++ Programs and Debugging in Linux This tutorial will give you a basic idea how to debug a program in Linux using GDB. As you are aware Visual Studio doesn’t run on Linux so you have to use...
4
by: =?Utf-8?B?TWlrZSBHYWxl?= | last post by:
VS 2008 initially didn't debug classic ASP. SP1 fixes this in some ways. You can debug if you select the debug option to "Start Without Debugging, then either attach the debugger manually or...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.