Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug tracing #652

Closed
mdblack98 opened this issue Apr 7, 2021 · 6 comments
Closed

Debug tracing #652

mdblack98 opened this issue Apr 7, 2021 · 6 comments

Comments

@mdblack98
Copy link
Contributor

See if we can provide a "level" indication in the debug messages to show the function call depth. Would make reviewing the debug info easier to trace.

So level 1 at top and each level down would increment by 1 on entry and decrement by 1 on exit.
This can probably be done via the ENTERFUNC and RETURNFUNC. But RETURNFUNC may be called without an associated ENTERFUNC and vice versa so a state machine will be needed to determine when to increment/decrement.
ENTERFUNC would be if (state==RETURNFUNC) ++depth
RETURNFUNC would be if (state == ENTERRFUNC) ++ depth
ENTERFUNC would set ENTERFUNC state
RETURNFUNC would set RETURNFUNC state
get_depth function/macro would return depth when state==ENTERFUNC and depth+1 when state==RETURNFUNC
ENTERFUNC would only increment depth if state==RETURNFUNC
RETURNFUNC would only decrement depth if state==ENTERFUNC

@mdblack98 mdblack98 added this to the 4.3 milestone Apr 7, 2021
@mdblack98 mdblack98 modified the milestones: 4.3, 4.4 Aug 1, 2021
@mdblack98 mdblack98 modified the milestones: 4.4, 4.5 Nov 24, 2021
@mdblack98 mdblack98 modified the milestones: 4.5, 4.6 Feb 28, 2022
@gvanem
Copy link
Contributor

gvanem commented Jun 6, 2022

And all instances of rig_debug(RIG_DEBUG_VERBOSE, "%s: _init called\n", __func__);
should IMHO be replaced with ENTERFUNC2 (or better yet ENTERFUNC2()).

I find that there is a huge amount of code being run when debug is disabled! E.g. in rig_send_raw(), the preprocessor
on clang-cl spits out these lined (edited and Astyled):

  do // for ENTERFUNC
  {
    ++rig->state.depth;

    do
    {
      strcpy (debugmsgsave2, debugmsgsave);
      snprintf (debugmsgsave, sizeof (debugmsgsave), "%.*s%d:%s(%d):%s entered\n", rig->state.depth, spaces(), rig->state.depth, (strrchr ("src/rig.c",
                '/') ? strrchrfile, '/') + 1 : "src/rig.c"), 7285, __func__);
      (rig_debug) (RIG_DEBUG_VERBOSE, "%.*s%d:%s(%d):%s entered\n", rig->state.depth, spaces(), rig->state.depth, (strrchr ("src/rig.c", '/') ? strrchrfile,
                   '/') + 1 : "src/rig.c"), 7285, __func__);
    }
    while (0);
  }
  while (0);


  int retval = write_block_sync (&rs->rigport, send, send_len);

  if (retval < 0)
  {
    do  // For rig_debug():
    {
      strcpy (debugmsgsave2, debugmsgsave);
      snprintf (debugmsgsave, sizeof (debugmsgsave), "%s: write_block_sync() failed, result=%d\n", __func__, retval);
      (rig_debug) (RIG_DEBUG_ERR, "%s: write_block_sync() failed, result=%d\n", __func__, retval);
    }
    while (0);
  }

@mdblack98
Copy link
Contributor Author

This provides intelligent debug information for apps like WSJTX/JTDX and others when errors occur. The strerror() function returns the debug history even if it's not turned on.
At this point I don't intend to eliminate this.

@gvanem
Copy link
Contributor

gvanem commented Jun 6, 2022

... function returns the debug history even if it's not turned on.

Into debugmsgsave[]? But what are debugmsgsave2[] and debugmsgsave3[] used for?
But I think strerror() is wrongly used on Windows in many places.

@mdblack98
Copy link
Contributor Author

mdblack98 commented Jun 6, 2022 via email

@gvanem
Copy link
Contributor

gvanem commented Jun 6, 2022

Where do think strerror is used incorrectly?

2 places in src/network.c for example.

@mdblack98
Copy link
Contributor Author

mdblack98 commented Oct 11, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants