Revision: 78021
          http://sourceforge.net/p/brlcad/code/78021
Author:   starseeker
Date:     2020-12-19 15:06:28 +0000 (Sat, 19 Dec 2020)
Log Message:
-----------
In the two cases where we may want/need a full path to an executable that can't 
be deduced by libbu (external user of libs with an applicaton location not in 
the CAD dirs) provide versions of the functions where the caller can pass in 
the path, per the TODO item.  Set up deprecation so we can eventually eliminate 
the old form in favor of the new.

Modified Paths:
--------------
    brlcad/trunk/CHANGES
    brlcad/trunk/include/bu/exit.h
    brlcad/trunk/src/libbu/backtrace.c
    brlcad/trunk/src/libbu/crashreport.c

Modified: brlcad/trunk/CHANGES
===================================================================
--- brlcad/trunk/CHANGES        2020-12-19 03:27:44 UTC (rev 78020)
+++ brlcad/trunk/CHANGES        2020-12-19 15:06:28 UTC (rev 78021)
@@ -141,6 +141,13 @@
         bg_polyline_2d_chull, bg_2d_chull, bg_3d_coplanar_chull,
         bg_3d_chull
 
+include/bu/exit.h
+        bu_backtrace and bu_crashreport will be replaced with versions
+        that take an optional parameter to pass in a full path from
+        the calling application.  (Currently available as
+        bu_backtrace_app and bu_crashreport_app, these will
+        replace existing versions after deprecation is complete.)
+
 MGED gui
        The following will be removed from MGED's menu bar (unused
        features, can be accomplished another way, or will be exposed

Modified: brlcad/trunk/include/bu/exit.h
===================================================================
--- brlcad/trunk/include/bu/exit.h      2020-12-19 03:27:44 UTC (rev 78020)
+++ brlcad/trunk/include/bu/exit.h      2020-12-19 15:06:28 UTC (rev 78021)
@@ -51,6 +51,15 @@
  */
 BU_EXPORT extern int bu_backtrace(FILE *fp);
 
+/**
+ * A version of bu_backtrace where the caller provides their own
+ * full path to their executable for passing to GDB, rather than
+ * having libbu attempt to determine that path.
+ *
+ * Passing NULL to argv0 makes the behavior identical to
+ * that of bu_backtrace.
+ */
+BU_EXPORT extern int bu_backtrace_app(FILE *fp, const char *argv0);
 
 /**
  * Adds a hook to the list of bu_bomb hooks.  The top (newest) one of these
@@ -138,6 +147,17 @@
  */
 BU_EXPORT extern int bu_crashreport(const char *filename);
 
+/**
+ * A version of bu_crashreport where the caller provides their own
+ * full path to their executable for passing to GDB, rather than
+ * having libbu attempt to determine that path.
+ *
+ * Passing NULL to argv0 makes the behavior identical to
+ * that of bu_crashreport.
+ */
+BU_EXPORT extern int bu_crashreport_app(const char *filename, const char 
*argv0);
+
+
 /** @} */
 
 __END_DECLS

Modified: brlcad/trunk/src/libbu/backtrace.c
===================================================================
--- brlcad/trunk/src/libbu/backtrace.c  2020-12-19 03:27:44 UTC (rev 78020)
+++ brlcad/trunk/src/libbu/backtrace.c  2020-12-19 15:06:28 UTC (rev 78021)
@@ -395,7 +395,7 @@
 
 
 int
-bu_backtrace(FILE *fp)
+bu_backtrace_app(FILE *fp, const char *argv0)
 {
     if (!fp) {
        fp = stdout;
@@ -440,11 +440,17 @@
 #endif
 
     if (have_gdb) {
+       const char *gdb_path = NULL;
        bu_strlcpy(debugger_args[0], path_gdb, MAXPATHLEN);
        /* MUST give gdb path to binary, otherwise attach bug causes
         * process kill on some platforms (e.g., FreeBSD9+AMD64)
         */
-       bu_strlcpy(debugger_args[1], bu_dir(NULL, 0, BU_DIR_BIN, 
bu_getprogname(), BU_DIR_EXT, NULL), MAXPATHLEN);
+       if (argv0) {
+           gdb_path = argv0;
+       } else {
+           gdb_path = bu_dir(NULL, 0, BU_DIR_BIN, bu_getprogname(), 
BU_DIR_EXT, NULL);
+       }
+       bu_strlcpy(debugger_args[1], gdb_path, MAXPATHLEN);
     } else if (have_lldb) {
        bu_strlcpy(debugger_args[0], path_lldb, MAXPATHLEN);
     }
@@ -535,6 +541,11 @@
     return 1;
 }
 
+int
+bu_backtrace(FILE *fp)
+{
+    return bu_backtrace_app(fp, NULL);
+}
 
 /*
  * Local Variables:

Modified: brlcad/trunk/src/libbu/crashreport.c
===================================================================
--- brlcad/trunk/src/libbu/crashreport.c        2020-12-19 03:27:44 UTC (rev 
78020)
+++ brlcad/trunk/src/libbu/crashreport.c        2020-12-19 15:06:28 UTC (rev 
78021)
@@ -50,7 +50,7 @@
 
 
 int
-bu_crashreport(const char *filename)
+bu_crashreport_app(const char *filename, const char *argv0)
 {
     if (UNLIKELY(!filename || strlen(filename) == 0)) {
        return 0;
@@ -59,7 +59,11 @@
     /* vat time ist? */
     (void)time(&now);
 
-    path = bu_dir(NULL, 0, BU_DIR_BIN, bu_getprogname(), BU_DIR_EXT, NULL);
+    if (argv0) {
+       path = argv0;
+    } else {
+       path = bu_dir(NULL, 0, BU_DIR_BIN, bu_getprogname(), BU_DIR_EXT, NULL);
+    }
 
     /* do our own expansion to avoid heap allocation */
     snprintf(buffer, CR_BUFSIZE, 
"******************************************\n\n"
@@ -181,6 +185,12 @@
     return 1;
 }
 
+int
+bu_crashreport(const char *filename)
+{
+    return bu_crashreport_app(filename, NULL);
+}
+
 /*
  * Local Variables:
  * tab-width: 8

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to