DaemonForums  

Go Back   DaemonForums > Miscellaneous > Programming

Programming C, bash, Python, Perl, PHP, Java, you name it.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 11th December 2017
Prevet Prevet is offline
Fdisk Soldier
 
Join Date: Oct 2017
Posts: 74
Default Need some help with OpenBSD's GDB

I am learning GDB but am having problems getting it's watch variable command working.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <SDL.h>

void die (const char *msg)
{
  fprintf (stderr, "err: %s\n", msg);
  exit (0x0f);
}

void test (const char *msg)
{
  fprintf (stderr, "err: %s\n", msg);
}


int main (int ac, char **av)
{
  int j = 0;
  if (SDL_Init (SDL_INIT_VIDEO))
    die (SDL_GetError ());
  j = j + 1;
  test ("hello");
  j = j + 1;
  puts ("SDL init -> OK");
  j = j + 1;
  return 0;
}

I set it to watch the variable j and from then on next appears to change to step, as it steps inside any function it encounters and clears the watch variable with the following message:

"Watchpoint 2 deleted because the program has left the block in
which its expression is valid."

What do OpenBSD programmers do about this?
Reply With Quote
  #2   (View Single Post)  
Old 11th December 2017
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 6,292
Default

Are you using the built-in version 6.3, or the 7.12 package? If installed, the latter is executed with egdb(1).

I have never set watch points, just break points, so I don't have any direct experience with this issue.
Reply With Quote
  #3   (View Single Post)  
Old 11th December 2017
Prevet Prevet is offline
Fdisk Soldier
 
Join Date: Oct 2017
Posts: 74
Default

Quote:
Originally Posted by jggimi View Post
Are you using the built-in version 6.3, or the 7.12 package? If installed, the latter is executed with egdb(1).

I have never set watch points, just break points, so I don't have any direct experience with this issue.
Thanks for replying. I was confused as to why the version numbers were different.

I was using the built in version however when I tried egdb just now, the watchpoints worked when I used them on simple code like below, but when I tried it with the SDL code above, it locked up when a function was called, so it might be fighting SDL, or perhaps it doesn't like libraries.

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

int wib(int no1, int no2)
{
  int result, diff;
  diff = no1 - no2;
  result = no1 / diff;
  return result;
}
int main(int argc, char *argv[])
{
  int value, div, result, i, total;
  value = 10;
  div = 6;
  total = 0;
  for(i = 0; i < 10; i++)
  {
    result = wib(value, div);
    total += result;
    div++;
    value--;
  }
  printf("%d wibed by %d equals %d\n", value, div, total);
  return 0;
}
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:32 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick