1
-bash-3.2$ uname -a
SunOS b2s-sol10spr-1 5.10 Generic_147147-26 sun4v sparc sun4v
-bash-3.2$ dbx -V
Sun DBX Debugger 8.0 SunOS_sparc 2014/10/21
For information about new features see `help changes'
To remove this message, put `dbxenv suppress_startup_message 8.0' in your .dbxrc
(dbx)

我遇到了一个奇怪的问题,调试器只是为函数参数和本地/成员变量显示完全错误的值。

这是一个示例回溯

=>[1] SQLGetDiagRecW(HandleType = -28417, Handle = 0x480000000101dfc1, RecNumber = -12288, Sqlstate = (nil), NativeError = 0xffffffff7fffdf, MessageText = 0x9100000001002bbd, BufferLength = -9583, TextLength = 0x380000000101da91), line 3154 in "CInterface.cpp"
  [2] extract_diag_error_w(htype = 3, handle = 0x3, connection = 0x1014d32c0, head = 0x101e5a5e0, return_code = -1, save_to_diag = 0), line 4447 in "__info.c"
  [3] function_return_ex(level = 3, handle = 0x101e5a1a0, ret_code = -1, save_to_diag = 0), line 4863 in "__info.c"
  [4] SQLExecDirectW(statement_handle = 0x101e5a1a0, statement_text = 0x101dacde0, text_length = -3), line 442 in "SQLExecDirectW.c"
  <truncated>

框架 1 位于有问题的共享库中,而其他框架位于 unixODBC libodbc.so 中

如果我们查看代码extract_diag_error_w(您可以从http://www.unixodbc.org/unixODBC-2.3.1.tar.gz获取代码,以下代码片段来自 DriverManager/__info.c)

ret = SQLGETDIAGRECW( connection,
                head -> handle_type,
                handle,
                rec_number,
                sqlstate,
                &native,
                msg1,
                sizeof( msg1 ),
                &len );

请注意,我们在其他地方有

#define SQLGETDIAGRECW(con,typ,han,rn,st,nat,msg,bl,tlp)\
                                    (con->functions[77].funcW)\
                                        (typ,han,rn,st,nat,msg,bl,tlp)

在 dbx 中,如果我转到第 2 帧并打印head -> handle_type,我会得到3,但如果我转到第 1 帧并打印HandleType,我会得到 -28417。

我希望 dbx,如果它找不到值(由于优化或 w/e,即使这一个调试版本),告诉我是这样的(<value optimized out>或类似的)。此外,我看到的每个值似乎都是错误的(我已经确认调试器通过控制流对我撒谎,有类似if (x < 0) throw ...;dbx 声称它是负数的代码,但不会抛出异常。

有问题的共享库是在另一台机器上构建的(而 unixODBC 是在本地构建的),所以可能涉及到这一点?它也是使用 gcc 构建的,我在构建 unixODBC 时使用了默认编译器(尽管我认为它也是 w/ gcc,因为它们都依赖于libgcc_s.so.1

有什么建议么?(我猜想更新 dbx 可能会起作用,但在这种环境下会很困难)。

编辑:这是一个带有局部变量的示例

(dbx) next
t@1 (l@1) stopped in Simba::Support::ODBCStringConverter::ConvertWStringToSQLWCHARString at line 64 in file "ODBCStringConverter.cpp"
   64       simba_int32 length = in_length;
(dbx) next
t@1 (l@1) stopped in Simba::Support::ODBCStringConverter::ConvertWStringToSQLWCHARString at line 66 in file "ODBCStringConverter.cpp"
   66       if (0 == in_length)
(dbx) print length
length = 11
(dbx) print in_length
in_length = 419430399
(dbx) next
t@1 (l@1) stopped in Simba::Support::ODBCStringConverter::ConvertWStringToSQLWCHARString at line 73 in file "ODBCStringConverter.cpp"
   73       else if (SIMBA_NTS == in_length)
(dbx) next
t@1 (l@1) stopped in Simba::Support::ODBCStringConverter::ConvertWStringToSQLWCHARString at line 79 in file "ODBCStringConverter.cpp"
   79       simba_int32 bufferBytes = length;
(dbx) next
t@1 (l@1) stopped in Simba::Support::ODBCStringConverter::ConvertWStringToSQLWCHARString at line 80 in file "ODBCStringConverter.cpp"
   80       if (!in_isLengthInBytes)
(dbx) print bufferBytes
bufferBytes = 1744830464
(dbx)

编辑2:这是构建麻烦库的方式(需要重建unixODBC,稍后会这样做)。

用于编译其中一个 .cpp 文件的示例命令(我删除了一堆包含目录)

/opt/csw/gcc4/bin/g++ -DSIZEOF_LONG_INT=8 -DSQL_WCHART_CONVERT -DHAVE_MEMMOVE -m64 -fPIC -pthread  -Wall -Wno-unknown-pragmas -DSIMBA -D_REENTRANT -DCLUNIX -DNDEBUG -D_POSIX_PTHREAD_SEMANTICS  -O0 -g -D_DEBUG  -c Common/QSTableMetadataFile.cpp -o Common/QSTableMetadataFile_solaris10sparc_gcc4_9_debug64.cpp.o

用于链接的命令(删除了一堆 .o 文件)

/opt/csw/gcc4/bin/g++ -DSIMBA -D_REENTRANT -m64 -fPIC -pthread  -Wall -Wno-unknown-pragmas  -lrt   -O0 -g  -shared -L/bamboo/bamboo-agent-home/xml-data/build-dir/ThirdParty/icu/53.1.x/solaris10sparc/gcc4_9/release64/lib -lstdc++ -licudata_sb64 -licui18n_sb64 -licuuc_sb64 -lpthread -lm -lsocket -lnsl -Wl,-M,exports_SunOS.map -Wl,-zallextract,/bamboo/bamboo-agent-home/xml-data/build-dir/SimbaEngine/Maintenance/10.1/Product/Lib/solaris10sparc/gcc4_9/debug64/libSimbaDSI.a,/bamboo/bamboo-agent-home/xml-data/build-dir/SimbaEngine/Maintenance/10.1/Product/Lib/solaris10sparc/gcc4_9/debug64/libSimbaSupport.a,/bamboo/bamboo-agent-home/xml-data/build-dir/SimbaEngine/Maintenance/10.1/Product/Lib/solaris10sparc/gcc4_9/debug64/libAEProcessor.a,/bamboo/bamboo-agent-home/xml-data/build-dir/SimbaEngine/Maintenance/10.1/Product/Lib/solaris10sparc/gcc4_9/debug64/libCore.a,/bamboo/bamboo-agent-home/xml-data/build-dir/SimbaEngine/Maintenance/10.1/Product/Lib/solaris10sparc/gcc4_9/debug64/libDSIExt.a,/bamboo/bamboo-agent-home/xml-data/build-dir/SimbaEngine/Maintenance/10.1/Product/Lib/solaris10sparc/gcc4_9/debug64/libExecutor.a,/bamboo/bamboo-agent-home/xml-data/build-dir/SimbaEngine/Maintenance/10.1/Product/Lib/solaris10sparc/gcc4_9/debug64/libParser.a,/bamboo/bamboo-agent-home/xml-data/build-dir/SimbaEngine/Maintenance/10.1/Product/Lib/solaris10sparc/gcc4_9/debug64/libSimbaODBC.a -Wl,-zweakextract  -o ../Bin/solaris10sparc/gcc4_9/debug64/libQuickstart64.so
4

0 回答 0