Author: vedantk Date: Thu May 31 15:09:01 2018 New Revision: 333700 URL: http://llvm.org/viewvc/llvm-project?rev=333700&view=rev Log: [IRMemoryMap] Test interleaved Mallocs and Frees
This adds a new command to the ir-memory-map tester: free <allocation-index> The argument to free is an index which identifies which live allocation to free. Index 0 identifies the first live allocation in the address space, index 1 identifies the second, etc. where the allocations are sorted in increasing order. For illustrative purposes, assume malloc returns monotonically increasing addresses. Here are some examples of how free would work: Example 1 --------- malloc 16 1 malloc 32 1 free 1 //< Free the 32-byte allocation. free 0 //< Next, free the 16-byte allocation. Example 2 --------- malloc 16 1 malloc 32 1 free 0 //< Free the 16-byte allocation. free 0 //< Next, free the 32-byte allocation. Added: lldb/trunk/lit/Expr/Inputs/ir-memory-map-mix-malloc-free Modified: lldb/trunk/lit/Expr/TestIRMemoryMap.test lldb/trunk/tools/lldb-test/lldb-test.cpp Added: lldb/trunk/lit/Expr/Inputs/ir-memory-map-mix-malloc-free URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Expr/Inputs/ir-memory-map-mix-malloc-free?rev=333700&view=auto ============================================================================== --- lldb/trunk/lit/Expr/Inputs/ir-memory-map-mix-malloc-free (added) +++ lldb/trunk/lit/Expr/Inputs/ir-memory-map-mix-malloc-free Thu May 31 15:09:01 2018 @@ -0,0 +1,275 @@ +# This file was generated by a slightly extended version of a script +# attached to https://reviews.llvm.org/D47508. + +malloc 2 4 +malloc 4095 128 +malloc 3 16 +malloc 8192 2 +malloc 1 128 +malloc 3 2 +free 3 +free 3 +malloc 32 2 +malloc 2 16 +free 1 +malloc 2048 2 +free 2 +malloc 2049 4 +malloc 4097 2 +malloc 2 16 +free 1 +free 6 +malloc 1 16 +malloc 33 128 +malloc 2 128 +malloc 2 16 +malloc 2 4 +malloc 2 4 +free 4 +malloc 4 4 +malloc 2 16 +free 3 +malloc 0 128 +free 6 +free 2 +malloc 33 2 +malloc 4095 2 +free 6 +malloc 2 4 +malloc 0 2 +free 1 +free 9 +free 5 +malloc 32 2 +malloc 4096 2 +free 2 +free 9 +free 6 +malloc 8192 16 +malloc 2 4 +malloc 4096 16 +free 10 +malloc 4 4 +free 7 +malloc 4 4 +malloc 8193 2 +malloc 1 2 +free 3 +free 7 +malloc 4096 2 +free 0 +malloc 4096 4 +free 3 +malloc 4097 128 +malloc 1 2 +malloc 4 2 +free 10 +free 8 +malloc 0 16 +malloc 2049 16 +free 9 +malloc 8193 16 +free 10 +free 1 +malloc 8193 2 +free 11 +malloc 3 16 +free 5 +malloc 33 128 +free 0 +malloc 2049 4 +malloc 1 128 +malloc 32 16 +free 1 +free 9 +malloc 2048 4 +free 0 +free 2 +malloc 5 4 +free 11 +malloc 2048 4 +malloc 4097 16 +malloc 8192 4 +free 2 +free 8 +free 11 +malloc 8192 4 +free 2 +malloc 8191 4 +malloc 32 128 +free 7 +malloc 4 16 +malloc 4096 128 +free 12 +malloc 2 4 +free 9 +malloc 8193 128 +malloc 4095 4 +malloc 2049 16 +malloc 2 4 +free 16 +malloc 0 128 +malloc 5 2 +malloc 2047 4 +malloc 2 2 +free 10 +malloc 0 128 +free 6 +malloc 2047 128 +free 11 +free 0 +free 9 +malloc 4 4 +malloc 3 2 +free 7 +malloc 1 128 +free 13 +malloc 8193 16 +malloc 4097 128 +free 15 +free 3 +malloc 1 2 +malloc 2049 4 +malloc 2048 2 +free 7 +malloc 31 4 +free 5 +free 14 +free 4 +free 10 +malloc 4 4 +free 6 +malloc 3 2 +malloc 1 128 +free 13 +malloc 4 16 +free 4 +free 8 +malloc 3 16 +free 13 +malloc 0 4 +free 8 +free 13 +malloc 1 2 +malloc 8192 128 +free 12 +malloc 2049 2 +malloc 1 16 +free 4 +free 7 +malloc 4 16 +malloc 4 128 +malloc 4096 16 +malloc 2048 16 +malloc 32 4 +malloc 8193 4 +free 2 +malloc 3 16 +malloc 8192 4 +free 1 +malloc 8191 2 +free 3 +malloc 8192 2 +malloc 8192 2 +free 3 +free 7 +malloc 31 4 +malloc 2049 2 +free 4 +free 3 +free 14 +free 1 +malloc 2048 4 +malloc 1 4 +malloc 1 4 +malloc 2 4 +malloc 4 16 +free 12 +free 14 +free 3 +free 0 +free 12 +free 10 +malloc 32 16 +free 5 +free 9 +free 4 +free 9 +free 3 +malloc 4096 16 +malloc 4 2 +free 12 +free 10 +free 3 +free 7 +malloc 4097 4 +malloc 4095 16 +free 3 +malloc 2047 16 +free 12 +malloc 8193 2 +free 2 +free 3 +malloc 0 4 +free 2 +free 9 +malloc 8192 16 +malloc 2 2 +malloc 4096 4 +malloc 5 128 +malloc 4095 4 +malloc 4095 4 +free 9 +malloc 32 4 +malloc 31 16 +free 15 +malloc 4097 16 +malloc 2048 128 +malloc 2048 2 +malloc 4096 128 +malloc 3 16 +free 2 +malloc 1 4 +malloc 3 4 +free 3 +malloc 31 2 +malloc 1 128 +free 21 +malloc 0 128 +free 8 +malloc 3 128 +free 5 +malloc 1 16 +free 9 +malloc 2048 4 +free 8 +free 4 +malloc 31 2 +malloc 1 16 +free 19 +malloc 2 4 +malloc 2 2 +free 8 +malloc 8193 16 +free 11 +free 8 +free 6 +free 12 +free 4 +free 0 +free 10 +free 1 +free 0 +free 5 +free 5 +free 3 +free 6 +free 1 +free 2 +free 6 +free 5 +free 4 +free 3 +free 1 +free 1 +free 0 Modified: lldb/trunk/lit/Expr/TestIRMemoryMap.test URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Expr/TestIRMemoryMap.test?rev=333700&r1=333699&r2=333700&view=diff ============================================================================== --- lldb/trunk/lit/Expr/TestIRMemoryMap.test (original) +++ lldb/trunk/lit/Expr/TestIRMemoryMap.test Thu May 31 15:09:01 2018 @@ -1,5 +1,10 @@ # RUN: %cxx %p/Inputs/call-function.cpp -g -o %t + # RUN: lldb-test ir-memory-map %t %S/Inputs/ir-memory-map-basic.test # RUN: lldb-test ir-memory-map -host-only %t %S/Inputs/ir-memory-map-basic.test + # RUN: lldb-test ir-memory-map %t %S/Inputs/ir-memory-map-overlap1.test # RUN: lldb-test ir-memory-map -host-only %t %S/Inputs/ir-memory-map-overlap1.test + +# RUN: lldb-test ir-memory-map %t %S/Inputs/ir-memory-map-mix-malloc-free +# RUN: lldb-test ir-memory-map -host-only %t %S/Inputs/ir-memory-map-mix-malloc-free Modified: lldb/trunk/tools/lldb-test/lldb-test.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-test/lldb-test.cpp?rev=333700&r1=333699&r2=333700&view=diff ============================================================================== --- lldb/trunk/tools/lldb-test/lldb-test.cpp (original) +++ lldb/trunk/tools/lldb-test/lldb-test.cpp Thu May 31 15:09:01 2018 @@ -169,9 +169,11 @@ static cl::opt<bool> UseHostOnlyAllocati using AllocationT = std::pair<addr_t, addr_t>; bool areAllocationsOverlapping(const AllocationT &L, const AllocationT &R); using AddrIntervalMap = - IntervalMap<addr_t, bool, 8, IntervalMapHalfOpenInfo<addr_t>>; + IntervalMap<addr_t, unsigned, 8, IntervalMapHalfOpenInfo<addr_t>>; bool evalMalloc(IRMemoryMap &IRMemMap, StringRef Line, AddrIntervalMap &AllocatedIntervals); +bool evalFree(IRMemoryMap &IRMemMap, StringRef Line, + AddrIntervalMap &AllocatedIntervals); int evaluateMemoryMapCommands(Debugger &Dbg); } // namespace irmemorymap @@ -569,9 +571,45 @@ bool opts::irmemorymap::evalMalloc(IRMem ++Probe; } - // Insert the new allocation into the interval map. + // Insert the new allocation into the interval map. Use unique allocation IDs + // to inhibit interval coalescing. + static unsigned AllocationID = 0; if (Size) - AllocatedIntervals.insert(Addr, EndOfRegion, true); + AllocatedIntervals.insert(Addr, EndOfRegion, AllocationID++); + + return true; +} + +bool opts::irmemorymap::evalFree(IRMemoryMap &IRMemMap, StringRef Line, + AddrIntervalMap &AllocatedIntervals) { + // ::= free <allocation-index> + size_t AllocIndex; + int Matches = sscanf(Line.data(), "free %zu", &AllocIndex); + if (Matches != 1) + return false; + + outs() << formatv("Command: free(allocation-index={0})\n", AllocIndex); + + // Find and free the AllocIndex-th allocation. + auto Probe = AllocatedIntervals.begin(); + for (size_t I = 0; I < AllocIndex && Probe != AllocatedIntervals.end(); ++I) + ++Probe; + + if (Probe == AllocatedIntervals.end()) { + outs() << "Free error: Invalid allocation index\n"; + exit(1); + } + + Status ST; + IRMemMap.Free(Probe.start(), ST); + if (ST.Fail()) { + outs() << formatv("Free error: {0}\n", ST); + exit(1); + } + + // Erase the allocation from the live interval map. + outs() << formatv("Free: [{0:x}, {1:x})\n", Probe.start(), Probe.stop()); + Probe.erase(); return true; } @@ -618,6 +656,9 @@ int opts::irmemorymap::evaluateMemoryMap if (evalMalloc(IRMemMap, Line, AllocatedIntervals)) continue; + if (evalFree(IRMemMap, Line, AllocatedIntervals)) + continue; + errs() << "Could not parse line: " << Line << "\n"; exit(1); } _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits