我正在维护一个必须运行 Alpha OpenVMS (7.3-2) 和 Itanium OpenVMS (8.4) 的应用程序。
它是用 C++ 编写的,编译器版本在 Alpha 上是 6.5-046,在 IA64 上是 7.4-004。

我遇到的问题是 LIB$SIGNAL()。一旦它发出致命消息的信号,程序就会中止。

首先是重现此代码的代码(作为生成和构建代码的 DCL 脚本):

$ create mtst.msg
.TITLE  Message file for MTST
.IDENT  'VERSION 1.1'
.FACILITY MTST,1 /PREFIX=MTST_
.SEVERITY INFORMATIONAL
HELLO       <Hello World> /fao_count=0
.SEVERITY SUCCESS
SUCCESS     <Opdracht succesvol uitgevoerd> /fao_count=0
.SEVERITY WARNING
WHOOPS      <Dit is een waarschuwing: !AZ> /fao_count=1
.SEVERITY ERROR
WHAAA       <Oeioeioei dat was op het randje> /fao_count=0
.SEVERITY   FATAL
AARGH       <Nu is het helemaal mis> /fao_count=0
.END
$!
$ create msgtest.h
#define __NEW_STARLET 1
#include<lib$routines.h>
#include<stsdef.h>

#pragma extern_model globalvalue

extern unsigned long MTST_HELLO;
extern unsigned long MTST_SUCCESS;
extern unsigned long MTST_WHOOPS;
extern unsigned long MTST_WHAAA;
extern unsigned long MTST_AARGH;

#pragma extern_model relaxed_refdef
$!
$ create msgctest.c
#include<msgtest.h>
#include<stdio>
#include<stdlib.h>

int main(void) {
    char* msgArgument = "Boe!";
    printf ("Test: info message...\n");
    LIB$SIGNAL(MTST_HELLO);
    printf("\n");

    printf ("Test: success message...\n");
    LIB$SIGNAL(MTST_SUCCESS);
    printf("\n");

    printf ("Test:  warning message...\n");
    LIB$SIGNAL(MTST_WHOOPS, 1, msgArgument);
    printf("\n");

    printf ("Test: error message...\n");
    LIB$SIGNAL(MTST_WHAAA);
    printf("\n");

    printf ("Test: fatal message...\n");
    LIB$SIGNAL(MTST_AARGH);
    printf("\n");

    printf ("Einde test!\n");
}
$!
$ create msgtest.cpp
#include<msgtest.h>
#include<iostream>
#include<stdlib.h>
using namespace std;
#include <chfdef.h>
int main(void) {
    char* msgArgument = "Boe!";
    cout << "Using IOStream:" << endl << "Test: info message..." << endl;
    LIB$SIGNAL(MTST_HELLO);
    cout << endl << "Test: success message..." << endl;
    LIB$SIGNAL(MTST_SUCCESS);
    cout << endl << "Test:  warning message..." << endl;
    LIB$SIGNAL(MTST_WHOOPS, 1, msgArgument);
    cout << endl << "Test: error message..." << endl;
    LIB$SIGNAL(MTST_WHAAA);
    cout << endl << "Test: fatal message..." << endl;
    LIB$SIGNAL(MTST_AARGH);

    // Next line is, of course, never displayed...
    cout << endl << "Einde test!" << endl;

}
$!
$! Compile the message file
$ message mtst
$!
$! As a reference, build an executable using the C-source. Will always work both on Alpha and Itanium
$ cc/lis=[] /include=[] msgctest.c /warn=(disa=dollarid)/notrace
$ link msgctest,mtst  /map=[]/cross/notrace
$!
$! Now build the C++ based exe.
$ cxx/lis=[]/reposi=[] /include=[] msgtest.cpp /warn=(disa=dollarid)/notrace/standard=strict_ansi
$! Using this compile statement it works on Itanium:
$! cxx/lis=[]/reposi=[] /include=[] msgtest.cpp /warn=(disa=dollarid)/notrace
$! Using this compile statement it fails again:
$! cxx/lis=[]/reposi=[] /include=[] msgtest.cpp /warn=(disa=dollarid)/notrace/define=(__USE_STD_IOSTREAM)
$ cxxlink msgtest,mtst /map=[]/cross/notrace
$!

C 源代码始终有效,并且在 Alpha 上两个脚本都有效。

在没有/STANDARD 的情况下编译时,它在 Itanium 上运行良好,但在原始程序中我在使用 iostream 时遇到了问题:我在那里需要 ANSI,但是使用/DEFINE=(__USE_STD_IOSTREAM) 进行编译又回到了原来的问题。
$r msgtest
Test: info message...
%MTST-I-HELLO, Hello World

Test: success message...
%MTST-S-SUCCESS, Opdracht succesvol uitgevoerd

Test: inwarningfo message...
%MTST-W-WHOOPS, Dit is een waarschuwing: Boe!

Test: error message...
%MTST-E-WHAAA, Oeioeioei dat was op het randje

Test: fatal message...
%CXXL-F-TERMINATING, terminate() or unexpected() called
$

我期望的是:
$ r msgctest
Test: info message...
%MTST-I-HELLO, Hello World

Test: success message...
%MTST-S-SUCCESS, Opdracht succesvol uitgevoerd

Test:  warning message...
%MTST-W-WHOOPS, Dit is een waarschuwing: Boe!

Test: error message...
%MTST-E-WHAAA, Oeioeioei dat was op het randje

Test: fatal message...
%MTST-F-AARGH, Nu is het helemaal mis
$

所以... %CPP-?-WTF,请帮忙:-/

提前致谢,
奥斯卡

注意:在我昨天发表的原始帖子中,有一个不同的脚本,其中包含更多测试代码,例如 try/catch。当然,正如 user2116290 在他/她的评论中所说,这改变了测试结果。
我将 DCL 脚本更改为原始测试以重现我在原始应用程序中看到的内容。

最佳答案

到目前为止,我没有看到问题。

$ sh symb x
  X = 134316076   Hex = 0801802C  Octal = 01000300054
$ search *.lis 0801802C/noheader
                         0801802C    13 AARGH       <Nu is het helemaal mis>

在 Alpha 上(我使用 HP C++ V7.1-015 for OpenVMS Alpha V8.3 进行了尝试),您发现了错误代码。然后你调用 abort() ,它发出 0x434 信号,即 OPCCUS,在我看来没问题。

在 Alpha 上,如果我删除 try/catch,则 c++ 程序的行为与 c 程序相同。我无法使用 C++ 访问 I64,因此我无法仔细检查 I64 上 abort abort() 的结果。它可能只是 %CXXL-F-TERMINATING。

新更新:

看起来严格 ansi 模式和标准 iostream 的组合会触发 C++ 捕获所有处理程序,它捕获致命的 VMS 条件/异常。在您的示例中,似乎可以通过以下方式禁用捕获 VMS 条件:
$ diff -ub old.cpp new.cpp
--- old.cpp     2015-11-11 19:42:52 +0100
+++ new.cpp     2015-11-11 19:49:10 +0100
@@ -1,8 +1,14 @@
 #include<msgtest.h>
 #include<iostream>
 #include<stdlib.h>
+#ifdef __ia64
+#include<cxx_exception.h>
+#endif
 using namespace std;
 int main(void) {
+#ifdef __ia64
+    cxxl$set_condition(pure_unix);
+#endif
     char* msgArgument = "Boe!";
     cout << "Using IOStream:" << endl << "Test: info message..." << endl;
     LIB$SIGNAL(MTST_HELLO);

编译、链接和运行更改后的示例:
    $ cxx /standard=strict_ansi/lis/warn=(disa=dollarid)/notrace/incl=[]/repo=[] new.cpp
    $ link /map=new/full=demangled/cross/notrace new, mtst
    $ r new
    Using IOStream:
    Test: info message...
    %MTST-I-HELLO, Hello World

    Test: success message...
    %MTST-S-SUCCESS, Opdracht succesvol uitgevoerd

    Test:  warning message...
    %MTST-W-WHOOPS, Dit is een waarschuwing: Boe!

    Test: error message...
    %MTST-E-WHAAA, Oeioeioei dat was op het randje

    Test: fatal message...
    %MTST-F-AARGH, Nu is het helemaal mis
    $

也许这也适合你。

关于c++ - 在 OpenVMS 上使用 -F-atals 的 LIB$SIGNAL 问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33522652/

10-12 07:40
查看更多