示例#1
0
void MemMgr::deinit() {
    isReady_ = false;

    std::ofstream mem_leaks("mem_leaks");
    std::ofstream calls("calls");

    std::cout << "--------------------------------------------------------------------------------" << std::endl;

    if (map_.empty()) {
        std::cout << std::endl << std::endl << "No memory leaks detected :)" << std::endl;
        return;
    }

    std::cout << std::endl << "WARNING: Memory leaks detected" << std::endl;
    std::cout << "Please run" << std::endl;
    std::cout << "\t$ leakfinder <EXECUTABLE>" << std::endl;

    for (PtrMap::iterator iter = map_.begin(); iter != map_.end(); ++iter) {
        // skip infos in unknown locations
        //Skip infos in paths starting '/' or '\' (these things are bugs, or strange or magic things in libs)
        mem_leaks << iter->second.caller_ << std::endl;
        calls  << iter->second.callNumber_ << std::endl;
/*        if (iter->second.line_ <= 0 || iter->second.filename_[0] == '/' || iter->second.filename_[0] == '\\') {
            mem_leaks_full  << "   " << iter->second.toString() << " at address: " << (uintptr_t) iter->first << std::endl;
        }
        else {
            mem_leaks           << "   " << iter->second.toString() << " at address: " << (uintptr_t) iter->first << std::endl;
            mem_leaks_full      << "   " << iter->second.toString() << " at address: " << (uintptr_t) iter->first << std::endl;
        }*/
    }

    calls.close();
    mem_leaks.close();
}
示例#2
0
iridium_method(File, each_line) {
  object self = local(self);
  object filename = local(filename); // From self
  object fn = local(fn);
  object str = NULL;
  FILE * f = get_file(context, self);
  size_t file_size = file_length(context, f, filename);
  char * buffer = GC_MALLOC((file_size+1)*sizeof(char));
  assert(buffer);
  int nchars;
  char * line = NULL;

  while ((nchars = getline(&buffer, &file_size, f)) != -1) {
    // Remove the newline, if present
    if (buffer[nchars-1] == '\n') {
      buffer[nchars-1] = 0;
    }
    line = GC_MALLOC((nchars + 1) * sizeof(char));
    assert(line);
    strncpy(line, buffer, nchars);
    str = IR_STRING(line);
    calls(context, fn, array_push(array_new(), str));
  }
  return NIL;
}
示例#3
0
void NeoCallProvider::clcc(bool, const QAtResult & result)
{
    QModemCall *ic = incomingCall();
    bool icMissing = true;

    int count = 0;

    // Find the current state of the call in the AT+CLCC results.
    QAtResultParser parser(result);
    while (parser.next("+CLCC:")) {
        uint id = parser.readNumeric();
        parser.readNumeric();   // dir
        uint state = parser.readNumeric();
        uint mode = parser.readNumeric();
        parser.readNumeric();   // mpty
        QString number = QAtUtils::decodeNumber(parser);
        QString callType = resolveCallMode(mode);
        //qDebug() << "=============== CLCC id=" << id << ", state =" << state <<
        //    ", mode=" << mode << ", number=" << number << "callType=" << callType;

        if (state == 4) {       // incoming
            if (ic && ic->number() == number) {
                icMissing = false;  // still ringing
            } else {            // new incoming call
                QModemCallProvider::ringing(number, callType, id);
                announceCall();
                clccTimer.start(CLCC_POLL_INTERVAL);
                return;
            }
        }
        count++;
    }

    // We still have call in incoming state
    if (ic) {
        if (icMissing) {
            qLog(Modem) << "Reporting missed call.";    // but it's missing in CLCC list
            ic->setState(QPhoneCall::Missed);   // make the call missed
            return;
        }
        clccTimer.start(CLCC_POLL_INTERVAL);    // continue with polling
        return;
    }
    // We still have some connected calls
    if (count > 0) {
        clccTimer.start(CLCC_POLL_INTERVAL);    // continue with polling
        return;
    }

    qLog(Modem) << "No more calls left";

    QList < QPhoneCallImpl * >list = calls();
    QList < QPhoneCallImpl * >::ConstIterator it;
    for (it = list.begin(); it != list.end(); ++it) {
        (*it)->setState(QPhoneCall::HangupRemote);
    }
}
示例#4
0
QVector<ApiTraceCall*>
TraceLoader::fetchFrameContents(ApiTraceFrame *currentFrame)
{
    Q_ASSERT(currentFrame);

    if (currentFrame->isLoaded()) {
        return currentFrame->calls();
    }

    if (m_parser.supportsOffsets()) {
        unsigned frameIdx = currentFrame->number;
        int numOfCalls = numberOfCallsInFrame(frameIdx);

        if (numOfCalls) {
            quint64 binaryDataSize = 0;
            QVector<ApiTraceCall*> calls(numOfCalls);
            const FrameBookmark &frameBookmark = m_frameBookmarks[frameIdx];

            m_parser.setBookmark(frameBookmark.start);

            trace::Call *call;
            int parsedCalls = 0;
            while ((call = m_parser.parse_call())) {
                ApiTraceCall *apiCall =
                    apiCallFromTraceCall(call, m_helpHash,
                                         currentFrame, this);
                calls[parsedCalls] = apiCall;
                Q_ASSERT(calls[parsedCalls]);
                if (apiCall->hasBinaryData()) {
                    QByteArray data =
                        apiCall->arguments()[
                            apiCall->binaryDataIndex()].toByteArray();
                    binaryDataSize += data.size();
                }

                ++parsedCalls;

                delete call;

                if (apiCall->flags() & trace::CALL_FLAG_END_FRAME) {
                    break;
                }

            }
            assert(parsedCalls == numOfCalls);
            Q_ASSERT(parsedCalls == calls.size());
            calls.squeeze();

            Q_ASSERT(parsedCalls == currentFrame->numChildrenToLoad());
            emit frameContentsLoaded(currentFrame,
                                     calls, binaryDataSize);
            return calls;
        }
    }
    return QVector<ApiTraceCall*>();
}
示例#5
0
Expr perform_inline(Expr e, const map<string, Function> &env,
                    const set<string> &inlines,
                    const vector<string> &order) {
    if (inlines.empty()) {
        return e;
    }

    bool funcs_to_inline = false;
    Expr inlined_expr = e;

    do {
        funcs_to_inline = false;
        // Find all the function calls in the current expression.
        FindAllCalls find;
        inlined_expr.accept(&find);
        const set<string> &calls_unsorted = find.funcs_called;

        vector<string> calls(calls_unsorted.begin(), calls_unsorted.end());
        // Sort 'calls' based on the realization order in descending order
        // if provided (i.e. last to be realized comes first).
        if (!order.empty()) {
            std::sort(calls.begin(), calls.end(),
                [&order](const string &lhs, const string &rhs){
                    const auto &iter_lhs = std::find(order.begin(), order.end(), lhs);
                    const auto &iter_rhs = std::find(order.begin(), order.end(), rhs);
                    return iter_lhs > iter_rhs;
                }
            );
        }

        // Check if any of the calls are in the set of functions to be inlined.
        // Inline from the last function to be realized to avoid extra
        // inlining works.
        for (const auto &call : calls) {
            if (inlines.find(call) != inlines.end()) {
                Function prod_func = env.at(call);
                // Impure functions cannot be inlined.
                internal_assert(prod_func.is_pure());
                // Inline the function call and set the flag to check for
                // further inlining opportunities.
                inlined_expr = inline_function(inlined_expr, prod_func);
                funcs_to_inline = true;
                break;
            }
        }
    } while (funcs_to_inline);

    return inlined_expr;
}
示例#6
0
  void addNeededFunctions(Module &m, Name name, std::set<Name> &needed) {
    if (needed.count(name)) {
      return;
    }
    needed.insert(name);

    auto function = m.getFunction(name);
    FindAll<Call> calls(function->body);
    for (auto* call : calls.list) {
      auto* called = m.getFunction(call->target);
      if (!called->imported()) {
        this->addNeededFunctions(m, call->target, needed);
      }
    }
  }
示例#7
0
Value Except::call(Value self, Value member, 
	short nargs, short nargnames, ushort* argnames, int each)
	{
	static Value As("As");
	static Value Callstack("Callstack");
	if (member == As)
		{
		argseach(nargs, nargnames, argnames, each);
		if (nargs != 1)
			except("usage: exception.As(string)");
		return new Except(*this, ARG(0).gcstr());
		}
	if (member == Callstack)
		{
		argseach(nargs, nargnames, argnames, each);
		NOARGS("exception.Callstack()");
		return calls();
		}
	else
		return SuString::call(self, member, nargs, nargnames, argnames, each);
	}
示例#8
0
static int
command(int argc, char *argv[])
{
    std::string output;
    trace::CallSet calls(trace::FREQUENCY_ALL);
    int thread = -1;
    int i;

    int opt;
    while ((opt = getopt_long(argc, argv, shortOptions, longOptions, NULL)) != -1) {
        switch (opt) {
        case 'h':
            usage();
            return 0;
        case CALLS_OPT:
            calls = trace::CallSet(optarg);
            break;
        case THREAD_OPT:
            thread = atoi(optarg);
            break;
        case 'o':
            output = optarg;
            break;
        default:
            std::cerr << "error: unexpected option `" << opt << "`\n";
            usage();
            return 1;
        }
    }

    if (optind >= argc) {
        std::cerr << "error: apitrace trim requires a trace file as an argument.\n";
        usage();
        return 1;
    }

    for (i = optind; i < argc; ++i) {
        trace::Parser p;
        if (!p.open(argv[i])) {
            std::cerr << "error: failed to open " << argv[i] << "\n";
            return 1;
        }

        if (output.empty()) {
            os::String base(argv[i]);
            base.trimExtension();

            output = std::string(base.str()) + std::string("-trim.trace");
        }

        trace::Writer writer;
        if (!writer.open(output.c_str())) {
            std::cerr << "error: failed to create " << argv[i] << "\n";
            return 1;
        }

        trace::Call *call;
        while ((call = p.parse_call())) {
            if (calls.contains(*call) &&
                (thread == -1 || call->thread_id == thread)) {
                writer.writeCall(call);
            }
            delete call;
        }

        std::cout << "Trimmed trace is available as " << output << "\n";
    }

    return 0;
}
示例#9
0
static int
command(int argc, char *argv[])
{
    std::string output;
    trace::CallSet calls(trace::FREQUENCY_ALL);
    int i;

    for (i = 1; i < argc;) {
        const char *arg = argv[i];

        if (arg[0] != '-') {
            break;
        }

        ++i;

        if (!strcmp(arg, "--")) {
            break;
        } else if (!strcmp(arg, "--help")) {
            usage();
            return 0;
        } else if (!strcmp(arg, "--calls")) {
            calls = trace::CallSet(argv[i++]);
        } else if (!strcmp(arg, "-o") ||
                   !strcmp(arg, "--output")) {
            output = argv[i++];
        } else {
            std::cerr << "error: unknown option " << arg << "\n";
            usage();
            return 1;
        }
    }

    if (i >= argc) {
        std::cerr << "Error: apitrace trim requires a trace file as an argument.\n";
        usage();
        return 1;
    }

    for ( ; i < argc; ++i) {
        trace::Parser p;
        if (!p.open(argv[i])) {
            std::cerr << "error: failed to open " << argv[i] << "\n";
            return 1;
        }

        if (output.empty()) {
            os::String base(argv[i]);
            base.trimExtension();

            output = std::string(base.str()) + std::string("-trim.trace");
        }

        trace::Writer writer;
        if (!writer.open(output.c_str())) {
            std::cerr << "error: failed to create " << argv[i] << "\n";
            return 1;
        }

        trace::Call *call;
        while ((call = p.parse_call())) {
            if (calls.contains(*call)) {
                writer.writeCall(call);
            }
            delete call;
        }

        std::cout << "Trimmed trace is available as " << output << "\n";
    }

    return 0;
}