diff options
author | Arne Juul <arnej@yahoo-inc.com> | 2018-06-12 12:50:28 +0200 |
---|---|---|
committer | Arne Juul <arnej@yahoo-inc.com> | 2018-06-12 13:51:45 +0200 |
commit | 016e584f0ad5a071e13d75eb8ad5ddb46b8c54f5 (patch) | |
tree | 869d4e4a4c4b8a9f9ef691b2980009017dece9e6 /vespalib | |
parent | 22796dddd3dc025018093783328ac87535ffecd9 (diff) |
use LOG_ABORT not just abort()
* abort() has the unfortunate effect that nothing is seen in the log,
just an event (which is usually not displayed); so ops people don't
see that the program is crashing at all.
* LOG_ABORT("message") will log an error with the message (and the file
and line) before calling abort(), so it's easy to see what happened.
* add or move <vespa/log/log.h> include and LOG_SETUP lines before
LOG_ABORT is used (or included).
Diffstat (limited to 'vespalib')
11 files changed, 35 insertions, 11 deletions
diff --git a/vespalib/src/apps/make_fixture_macros/make_fixture_macros.cpp b/vespalib/src/apps/make_fixture_macros/make_fixture_macros.cpp index 6e23bd46d71..d15b925d31a 100644 --- a/vespalib/src/apps/make_fixture_macros/make_fixture_macros.cpp +++ b/vespalib/src/apps/make_fixture_macros/make_fixture_macros.cpp @@ -4,6 +4,9 @@ #include <stdlib.h> #include <algorithm> +#include <vespa/log/log.h> +LOG_SETUP("make_fixture_macros"); + void out(const char *str) { fprintf(stdout, "%s", str); } void out_n(const char *str, int n) { fprintf(stdout, str, n); } void out_nn(const char *str, int n) { fprintf(stdout, str, n, n); } @@ -24,7 +27,7 @@ void out_list(const char *pre, const char *str, const char *sep, const char *pos case 0: out(str); break; case 1: out_n(str, i + 1); break; case 2: out_nn(str, i + 1); break; - default: abort(); + default: LOG_ABORT("should not be reached"); } } out_if(post, n > 0); diff --git a/vespalib/src/tests/delegatelist/delegatelist.cpp b/vespalib/src/tests/delegatelist/delegatelist.cpp index 8ee68b80ed0..ba1a2049794 100644 --- a/vespalib/src/tests/delegatelist/delegatelist.cpp +++ b/vespalib/src/tests/delegatelist/delegatelist.cpp @@ -290,7 +290,7 @@ Actor::perform(int cnt, int start, const CmdList &cmdList) return cmdList.size(); break; default: - abort(); // that does not seem to work + LOG_ABORT("should not be reached"); // that does not seem to work } } } diff --git a/vespalib/src/vespa/vespalib/data/slime/binary_format.cpp b/vespalib/src/vespa/vespalib/data/slime/binary_format.cpp index 39ee8a40d4a..d6e12c7ab59 100644 --- a/vespalib/src/vespa/vespalib/data/slime/binary_format.cpp +++ b/vespalib/src/vespa/vespalib/data/slime/binary_format.cpp @@ -4,6 +4,9 @@ #include "slime.h" #include <vespa/vespalib/data/memory_input.h> +#include <vespa/log/log.h> +LOG_SETUP(".vespalib.data.slime.binary_format"); + namespace vespalib { namespace slime { @@ -55,7 +58,7 @@ struct BinaryEncoder : public ArrayTraverser, case ARRAY::ID: return encodeArray(inspector); case OBJECT::ID: return encodeObject(inspector); } - abort(); // should not be reached + LOG_ABORT("should not be reached"); // should not be reached } void encodeSymbolTable(const Slime &slime) { size_t numSymbols = slime.symbols(); @@ -170,7 +173,7 @@ struct BinaryDecoder : SymbolHandler<remap_symbols>::type { case ARRAY::ID: return decodeArray(inserter, meta); case OBJECT::ID: return decodeObject(inserter, meta); } - abort(); // code should not be reached + LOG_ABORT("should not be reached"); // code should not be reached } void decodeValue(const Inserter &inserter) { diff --git a/vespalib/src/vespa/vespalib/data/slime/inject.cpp b/vespalib/src/vespa/vespalib/data/slime/inject.cpp index de1bd840c5a..febd9058b00 100644 --- a/vespalib/src/vespa/vespalib/data/slime/inject.cpp +++ b/vespalib/src/vespa/vespalib/data/slime/inject.cpp @@ -6,6 +6,9 @@ #include "object_traverser.h" #include <cstdlib> +#include <vespa/log/log.h> +LOG_SETUP(".vespalib.data.slime.inject"); + namespace vespalib { namespace slime { @@ -48,7 +51,7 @@ void injectValue(const Inserter &inserter, const Inspector &inspector, const Ins case ARRAY::ID: return injectArray(inserter, inspector, guard); case OBJECT::ID: return injectObject(inserter, inspector, guard); } - abort(); // should not be reached + LOG_ABORT("should not be reached"); // should not be reached } void diff --git a/vespalib/src/vespa/vespalib/data/slime/json_format.cpp b/vespalib/src/vespa/vespalib/data/slime/json_format.cpp index 72b494e2479..29ab55143e0 100644 --- a/vespalib/src/vespa/vespalib/data/slime/json_format.cpp +++ b/vespalib/src/vespa/vespalib/data/slime/json_format.cpp @@ -9,6 +9,9 @@ #include <cmath> #include <sstream> +#include <vespa/log/log.h> +LOG_SETUP(".vespalib.data.slime.json_format"); + namespace vespalib::slime { namespace { @@ -133,7 +136,7 @@ struct JsonEncoder : public ArrayTraverser, case ARRAY::ID: return encodeARRAY(inspector); case OBJECT::ID: return encodeOBJECT(inspector); } - abort(); // should not be reached + LOG_ABORT("should not be reached"); // should not be reached } void entry(size_t idx, const Inspector &inspector) override; void field(const Memory &symbol_name, const Inspector &inspector) override; diff --git a/vespalib/src/vespa/vespalib/hwaccelrated/iaccelrated.cpp b/vespalib/src/vespa/vespalib/hwaccelrated/iaccelrated.cpp index d2ef5297d72..aae277b48d8 100644 --- a/vespalib/src/vespa/vespalib/hwaccelrated/iaccelrated.cpp +++ b/vespalib/src/vespa/vespalib/hwaccelrated/iaccelrated.cpp @@ -7,6 +7,9 @@ #include "avx2.h" #include "avx512.h" +#include <vespa/log/log.h> +LOG_SETUP(".vespalib.hwaccelrated"); + namespace vespalib::hwaccelrated { namespace { @@ -57,7 +60,7 @@ void verifyAccelrator(const IAccelrated & accel) T hwComputedSum(accel.dotProduct(&a[j], &b[j], testLength - j)); if (sum != hwComputedSum) { fprintf(stderr, "Accelrator is not computing dotproduct correctly.\n"); - abort(); + LOG_ABORT("should not be reached"); } } delete [] a; diff --git a/vespalib/src/vespa/vespalib/net/selector.cpp b/vespalib/src/vespa/vespalib/net/selector.cpp index e59638b6144..5d73396bc7d 100644 --- a/vespalib/src/vespa/vespalib/net/selector.cpp +++ b/vespalib/src/vespa/vespalib/net/selector.cpp @@ -7,6 +7,7 @@ #include <cstring> #include <unistd.h> #include <fcntl.h> +#include <vespa/log/log.h> namespace vespalib { @@ -19,7 +20,7 @@ uint32_t maybe(uint32_t value, bool yes) { return yes ? value : 0; } void check(int res) { if (res == -1) { if (errno == ENOMEM) { - abort(); + LOG_ABORT("out of memory"); } } } diff --git a/vespalib/src/vespa/vespalib/stllike/asciistream.cpp b/vespalib/src/vespa/vespalib/stllike/asciistream.cpp index 7b895f3eb73..cf7fdebb401 100644 --- a/vespalib/src/vespa/vespalib/stllike/asciistream.cpp +++ b/vespalib/src/vespa/vespalib/stllike/asciistream.cpp @@ -10,6 +10,8 @@ #include <limits> #include <stdexcept> #include <cassert> +#include <vespa/log/log.h> +LOG_SETUP(".vespalib.stllike.asciistream"); namespace vespalib { @@ -521,7 +523,7 @@ void asciistream::write(const void * buf, size_t len) if (_wbuf.empty()) { _wbuf = _rbuf; // Read only to RW } else { - abort(); // Impossible + LOG_ABORT("should not be reached"); // Impossible } } _wbuf.append(buf, len); diff --git a/vespalib/src/vespa/vespalib/testkit/test_master.cpp b/vespalib/src/vespa/vespalib/testkit/test_master.cpp index d5309845dfd..49ee3d6da94 100644 --- a/vespalib/src/vespa/vespalib/testkit/test_master.cpp +++ b/vespalib/src/vespa/vespalib/testkit/test_master.cpp @@ -3,6 +3,8 @@ #include "test_master.h" #include <vespa/vespalib/util/barrier.h> #include <cstring> +#include <vespa/log/log.h> +LOG_SETUP(".vespalib.testkit.test_master"); namespace vespalib { @@ -111,7 +113,7 @@ TestMaster::handleFailure(const vespalib::LockGuard &guard, bool fatal) } fprintf(stderr, "%s: ERROR: vital check failed, aborting\n", _name.c_str()); - abort(); + LOG_ABORT("should not be reached"); } } diff --git a/vespalib/src/vespa/vespalib/testkit/time_bomb.cpp b/vespalib/src/vespa/vespalib/testkit/time_bomb.cpp index a9191a8fc4f..cbefa285384 100644 --- a/vespalib/src/vespa/vespalib/testkit/time_bomb.cpp +++ b/vespalib/src/vespa/vespalib/testkit/time_bomb.cpp @@ -1,6 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "time_bomb.h" +#include <vespa/log/log.h> +LOG_SETUP(".vespalib.testkit.time_bomb"); namespace vespalib { @@ -20,7 +22,7 @@ void bomb(Gate &gate, size_t seconds) { } } fprintf(stderr, "BOOM!\n"); - abort(); + LOG_ABORT("should not be reached"); } } // namespace vespalib::<unnamed> diff --git a/vespalib/src/vespa/vespalib/util/hashmap.h b/vespalib/src/vespa/vespalib/util/hashmap.h index ed686497458..44db499f372 100644 --- a/vespalib/src/vespa/vespalib/util/hashmap.h +++ b/vespalib/src/vespa/vespalib/util/hashmap.h @@ -4,6 +4,7 @@ #include "hashmapdata.h" #include <cstring> #include <cstdlib> +#include <assert.h> /** * @brief namespace for generic Vespa library @@ -350,6 +351,7 @@ HashMap<T>::maxDepth() const } if (d > ret) ret = d; } + assert(cnt == _entryCnt); if (cnt != _entryCnt) abort(); return ret; } |