forked from rr-debugger/rr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
1471 lines (1366 loc) · 42.2 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# *-* Mode: cmake; *-*
cmake_minimum_required(VERSION 3.1.0)
project(rr C CXX ASM)
# "Do not add flags to export symbols from executables without the ENABLE_EXPORTS target property."
# This avoids linking executables with -rdynamic. -rdynamic has been observed
# to cause rr_exec_stub to be linked with the dynamic linker with some
# version(s) of clang (but linked to an incorrect file name, causing
# exec of rr_exec_stub to fail).
if(POLICY CMP0065)
cmake_policy(SET CMP0065 NEW)
endif()
# On single configuration generators, make Debug the default configuration
if(NOT CMAKE_CONFIGURATION_TYPES)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Whether to build in `Debug` or `Release` mode." FORCE)
endif()
endif()
enable_testing()
set(BUILD_SHARED_LIBS ON)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib/rr)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(BUILD_TESTS ON CACHE BOOL "Build tests")
set(WILL_RUN_TESTS ${BUILD_TESTS} CACHE BOOL "Run tests")
# CAREFUL! "-" is an invalid character in RPM package names, while
# debian is happy with it. However, "_" is illegal in debs, while RPM
# is cool with it. Sigh.
set(rr_VERSION_MAJOR 5)
set(rr_VERSION_MINOR 2)
set(rr_VERSION_PATCH 0)
add_definitions(-DRR_VERSION="${rr_VERSION_MAJOR}.${rr_VERSION_MINOR}.${rr_VERSION_PATCH}")
execute_process(
COMMAND git rev-parse HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_REVISION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
configure_file(
${CMAKE_SOURCE_DIR}/src/git_revision.h.in
${CMAKE_BINARY_DIR}/git_revision.h
)
set(FLAGS_COMMON "-msse2 -D__MMX__ -D__SSE__ -D__SSE2__ -D__USE_LARGEFILE64 -pthread -g3")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAGS_COMMON} -Wstrict-prototypes -std=gnu11")
# Define __STDC_LIMIT_MACROS so |#include <stdint.h>| works as expected.
# Define __STDC_FORMAT_MACROS so |#include <inttypes.h>| works as expected.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAGS_COMMON} -D__STDC_LIMIT_MACROS -D__STDC_FORMAT_MACROS -std=c++14")
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -g3")
set(RR_FLAGS_DEBUG "-Wall -Wextra -Werror -O0 -DDEBUG -UNDEBUG")
set(RR_FLAGS_RELEASE "-Wall -Wextra -O2 -UDEBUG -DNDEBUG")
set(RR_TEST_FLAGS "${RR_FLAGS_DEBUG}")
string(TOLOWER ${CMAKE_BUILD_TYPE} LOWERCASE_CMAKE_BUILD_TYPE)
if(LOWERCASE_CMAKE_BUILD_TYPE STREQUAL "debug")
set(RR_FLAGS ${RR_FLAGS_DEBUG})
else()
set(RR_FLAGS ${RR_FLAGS_RELEASE})
endif()
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-command-line-argument")
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-command-line-argument")
endif()
if (CMAKE_ASM_COMPILER_ID STREQUAL "Clang")
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -fno-integrated-as")
endif()
option(force32bit "Force a 32-bit rr build, rather than both 64 and 32-bit. rr will only be able to record and replay 32-bit processes.")
option(disable32bit "On a 64-bit platform, avoid requiring a 32-bit cross-compilation toolchain by not building 32-bit components. rr will be able to record 32-bit processes but not replay them.")
if(force32bit)
set(rr_32BIT true)
set(rr_64BIT false)
set(rr_MBITNESS_OPTION -m32)
else()
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
if(disable32bit)
set(rr_32BIT false)
else()
set(rr_32BIT true)
endif()
set(rr_64BIT true)
else()
set(rr_32BIT true)
set(rr_64BIT false)
endif()
set(rr_MBITNESS_OPTION)
endif()
option(staticlibs "Force usage of static linkage for non-standard libraries like capnproto")
# Check that compiling 32-bit code on a 64-bit target works, if required.
if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64" AND rr_32BIT)
# try_compile won't accept LINK_FLAGS, so do this manually.
file(WRITE "${CMAKE_BINARY_DIR}/test32.c" "int main() { return 0; }")
execute_process(COMMAND ${CMAKE_C_COMPILER} -o ${CMAKE_BINARY_DIR}/test32 ${CMAKE_BINARY_DIR}/test32.c -m32
RESULT_VARIABLE COMPILER_32BIT_RESULT)
if(NOT (COMPILER_32BIT_RESULT EQUAL 0))
message(FATAL_ERROR "Your toolchain doesn't support 32-bit cross-compilation. Install the required packages or pass -Ddisable32bit=ON to cmake.")
endif()
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${rr_MBITNESS_OPTION}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${rr_MBITNESS_OPTION}")
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} ${rr_MBITNESS_OPTION}")
find_package(PkgConfig REQUIRED)
# If we're cross-compiling a 32-bit rr build on a 64-bit host we need
# to ensure we're looking for the right libraries.
# This has been tested on Ubuntu and Fedora.
if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64" AND NOT rr_64BIT)
set(LIBDIR32_CANDIDATES
/usr/lib/i386-linux-gnu/pkgconfig/
/usr/lib/pkgconfig/
)
foreach(libdir ${LIBDIR32_CANDIDATES})
if(IS_DIRECTORY ${libdir})
set(ENV{PKG_CONFIG_LIBDIR} ${libdir})
break()
endif()
endforeach(libdir)
if(NOT DEFINED ENV{PKG_CONFIG_LIBDIR})
message(FATAL_ERROR "Couldn't find a suitable 32-bit pkgconfig lib dir. You probably need to install a 32-bit pkgconfig package (pkgconfig.i686 for Fedora or pkg-config:i386 for Ubuntu")
endif()
endif()
find_program(CAPNP capnp)
if(${CAPNP} STREQUAL "CAPNP-NOTFOUND")
message(FATAL_ERROR "Can't find 'capnp' command; install Capnproto packages? https://github.com/mozilla/rr/wiki/Building-And-Installing#tldr")
endif()
set(REQUIRED_LIBS
capnp
)
foreach(required_lib ${REQUIRED_LIBS})
string(TOUPPER ${required_lib} PKG)
pkg_check_modules(${PKG} REQUIRED ${required_lib})
if(staticlibs)
string(REPLACE ";" " " ${PKG}_STATIC_CFLAGS "${${PKG}_STATIC_CFLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${${PKG}_STATIC_CFLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${${PKG}_STATIC_CFLAGS}")
else()
string(REPLACE ";" " " ${PKG}_CFLAGS "${${PKG}_CFLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${${PKG}_CFLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${${PKG}_CFLAGS}")
endif()
endforeach(required_lib)
# ==== brotli ====
set(BROTLI_FILES
third-party/brotli/common/dictionary.c
third-party/brotli/dec/bit_reader.c
third-party/brotli/dec/decode.c
third-party/brotli/dec/huffman.c
third-party/brotli/dec/state.c
third-party/brotli/enc/backward_references.c
third-party/brotli/enc/backward_references.h
third-party/brotli/enc/backward_references_hq.c
third-party/brotli/enc/backward_references_hq.h
third-party/brotli/enc/backward_references_inc.h
third-party/brotli/enc/bit_cost.c
third-party/brotli/enc/bit_cost.h
third-party/brotli/enc/bit_cost_inc.h
third-party/brotli/enc/block_encoder_inc.h
third-party/brotli/enc/block_splitter.c
third-party/brotli/enc/block_splitter.h
third-party/brotli/enc/block_splitter_inc.h
third-party/brotli/enc/brotli_bit_stream.c
third-party/brotli/enc/brotli_bit_stream.h
third-party/brotli/enc/cluster.c
third-party/brotli/enc/cluster.h
third-party/brotli/enc/cluster_inc.h
third-party/brotli/enc/command.h
third-party/brotli/enc/compress_fragment.c
third-party/brotli/enc/compress_fragment.h
third-party/brotli/enc/compress_fragment_two_pass.c
third-party/brotli/enc/compress_fragment_two_pass.h
third-party/brotli/enc/context.h
third-party/brotli/enc/dictionary_hash.c
third-party/brotli/enc/dictionary_hash.h
third-party/brotli/enc/encode.c
third-party/brotli/enc/entropy_encode.c
third-party/brotli/enc/entropy_encode.h
third-party/brotli/enc/entropy_encode_static.h
third-party/brotli/enc/fast_log.h
third-party/brotli/enc/find_match_length.h
third-party/brotli/enc/hash_forgetful_chain_inc.h
third-party/brotli/enc/hash.h
third-party/brotli/enc/hash_longest_match64_inc.h
third-party/brotli/enc/hash_longest_match_inc.h
third-party/brotli/enc/hash_longest_match_quickly_inc.h
third-party/brotli/enc/hash_to_binary_tree_inc.h
third-party/brotli/enc/histogram.c
third-party/brotli/enc/histogram.h
third-party/brotli/enc/histogram_inc.h
third-party/brotli/enc/literal_cost.c
third-party/brotli/enc/literal_cost.h
third-party/brotli/enc/memory.c
third-party/brotli/enc/memory.h
third-party/brotli/enc/metablock.c
third-party/brotli/enc/metablock.h
third-party/brotli/enc/metablock_inc.h
third-party/brotli/enc/port.h
third-party/brotli/enc/prefix.h
third-party/brotli/enc/quality.h
third-party/brotli/enc/ringbuffer.h
third-party/brotli/enc/static_dict.c
third-party/brotli/enc/static_dict.h
third-party/brotli/enc/static_dict_lut.h
third-party/brotli/enc/utf8_util.c
third-party/brotli/enc/utf8_util.h
third-party/brotli/enc/write_bits.h
)
add_library(brotli STATIC ${BROTLI_FILES})
set_source_files_properties(${BROTLI_FILES}
PROPERTIES COMPILE_FLAGS ${RR_FLAGS_RELEASE})
# ==== brotli ====
find_path(SECCOMP NAMES "linux/seccomp.h")
if(NOT SECCOMP)
message(FATAL_ERROR "Couldn't find linux/seccomp.h. You may need to upgrade your kernel.")
endif()
# Check for Python >=2.7 but not Python 3.
find_package(PythonInterp 3.0 QUIET)
find_package(PythonInterp 2.7 REQUIRED)
execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c" "# nothing"
RESULT_VARIABLE python_status)
if(python_status)
message(FATAL_ERROR "Couldn't run python interpreter ${PYTHON_EXECUTABLE}.")
endif()
# Check for required Python modules
if(WILL_RUN_TESTS)
if(NOT BUILD_TESTS)
message(FATAL_ERROR "Running tests requires building them")
endif()
set(REQUIRED_PYTHON_MODULES
pexpect
)
else()
set(REQUIRED_PYTHON_MODULES)
endif()
foreach(py_module ${REQUIRED_PYTHON_MODULES})
execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"
"import ${py_module}"
RESULT_VARIABLE module_status)
if(module_status)
message(FATAL_ERROR "Couldn't find required Python module ${py_module}.")
endif()
endforeach(py_module)
if(WILL_RUN_TESTS)
# Check for gdb
execute_process(COMMAND "gdb" "--version" RESULT_VARIABLE module_status OUTPUT_QUIET)
if(module_status)
message(FATAL_ERROR "Couldn't find gdb.")
endif()
endif()
set(PRELOAD_COMPILE_FLAGS "-fno-stack-protector")
if (DEBUG_PRELOAD_LIB)
set(PRELOAD_COMPILE_FLAGS "${PRELOAD_COMPILE_FLAGS} ${RR_FLAGS_DEBUG}")
else()
set(PRELOAD_COMPILE_FLAGS "${PRELOAD_COMPILE_FLAGS} ${RR_FLAGS_RELEASE}")
endif()
set_source_files_properties(src/preload/syscallbuf.c
src/preload/overrides.c
PROPERTIES COMPILE_FLAGS ${PRELOAD_COMPILE_FLAGS})
include_directories("${PROJECT_SOURCE_DIR}/include")
include_directories("${PROJECT_SOURCE_DIR}/third-party/proc-service")
include_directories("${PROJECT_SOURCE_DIR}/third-party/brotli/include")
# We need to know where our generated files are.
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
# Order matters here! syscall_hook.S must be immediately before syscallbuf.c,
# breakpoint_table.S must be before overrides.c, which must be last.
set(PRELOAD_FILES
syscall_hook.S
syscallbuf.c
raw_syscall.S
breakpoint_table.S
overrides.c
)
set(PRELOAD_SOURCE_FILES
${PRELOAD_FILES}
preload_interface.h
syscallbuf.h
)
add_library(rrpreload)
foreach(file ${PRELOAD_FILES})
target_sources(rrpreload PUBLIC "src/preload/${file}")
endforeach(file)
set_target_properties(rrpreload PROPERTIES LINK_FLAGS "-nostartfiles")
# Ensure that CMake knows about our generated files.
#
# Alphabetical, please.
set(GENERATED_FILES
AssemblyTemplates.generated
CheckSyscallNumbers.generated
SyscallEnumsX64.generated
SyscallEnumsX86.generated
SyscallEnumsForTestsX64.generated
SyscallEnumsForTestsX86.generated
SyscallHelperFunctions.generated
SyscallnameArch.generated
SyscallRecordCase.generated
)
foreach(generated_file ${GENERATED_FILES})
set_source_files_properties(${generated_file}
PROPERTIES GENERATED true HEADER_FILE_ONLY true)
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${generated_file}"
COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/src/generate_syscalls.py"
"${CMAKE_CURRENT_BINARY_DIR}/${generated_file}"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/generate_syscalls.py"
"${CMAKE_CURRENT_SOURCE_DIR}/src/syscalls.py"
"${CMAKE_CURRENT_SOURCE_DIR}/src/assembly_templates.py")
endforeach(generated_file)
add_custom_target(Generated DEPENDS ${GENERATED_FILES})
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/bin/rr_page_64"
COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/src/generate_rr_page.py"
"${CMAKE_CURRENT_BINARY_DIR}/bin/rr_page_64"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/generate_rr_page.py")
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/bin/rr_page_32"
COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/src/generate_rr_page.py"
"${CMAKE_CURRENT_BINARY_DIR}/bin/rr_page_32"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/generate_rr_page.py")
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/bin/rr_page_64_replay"
COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/src/generate_rr_page.py"
"${CMAKE_CURRENT_BINARY_DIR}/bin/rr_page_64_replay"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/generate_rr_page.py")
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/bin/rr_page_32_replay"
COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/src/generate_rr_page.py"
"${CMAKE_CURRENT_BINARY_DIR}/bin/rr_page_32_replay"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/generate_rr_page.py")
add_custom_target(Pages DEPENDS
"${CMAKE_CURRENT_BINARY_DIR}/bin/rr_page_32"
"${CMAKE_CURRENT_BINARY_DIR}/bin/rr_page_64"
"${CMAKE_CURRENT_BINARY_DIR}/bin/rr_page_32_replay"
"${CMAKE_CURRENT_BINARY_DIR}/bin/rr_page_64_replay")
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/rr_trace.capnp.c++"
"${CMAKE_CURRENT_BINARY_DIR}/rr_trace.capnp.h"
COMMAND capnp compile
"--src-prefix=${CMAKE_CURRENT_SOURCE_DIR}/src"
"-oc++:${CMAKE_CURRENT_BINARY_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/src/rr_trace.capnp"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/rr_trace.capnp")
set_source_files_properties("${CMAKE_CURRENT_BINARY_DIR}/rr_trace.capnp.c++"
PROPERTIES GENERATED true)
set_source_files_properties("${CMAKE_CURRENT_BINARY_DIR}/rr_trace.capnp.h"
PROPERTIES GENERATED true HEADER_FILE_ONLY true)
set(RR_SOURCES
src/test/cpuid_loop.S
src/AddressSpace.cc
src/AutoRemoteSyscalls.cc
src/Command.cc
src/CompressedReader.cc
src/CompressedWriter.cc
src/CPUFeaturesCommand.cc
src/CPUIDBugDetector.cc
src/DiversionSession.cc
src/DumpCommand.cc
src/ElfReader.cc
src/EmuFs.cc
src/Event.cc
src/ExtraRegisters.cc
src/fast_forward.cc
src/FdTable.cc
src/FileMonitor.cc
src/Flags.cc
src/ftrace.cc
src/GdbCommand.cc
src/GdbCommandHandler.cc
src/GdbConnection.cc
src/GdbExpression.cc
src/GdbInitCommand.cc
src/GdbServer.cc
src/HasTaskSet.cc
src/HelpCommand.cc
src/kernel_abi.cc
src/kernel_metadata.cc
src/log.cc
src/LsCommand.cc
src/MagicSaveDataMonitor.cc
src/MmappedFileMonitor.cc
src/MonitoredSharedMemory.cc
src/Monkeypatcher.cc
src/PackCommand.cc
src/PerfCounters.cc
src/ProcFdDirMonitor.cc
src/ProcMemMonitor.cc
src/PsCommand.cc
src/RecordCommand.cc
src/RecordSession.cc
src/record_signal.cc
src/record_syscall.cc
src/RecordTask.cc
src/Registers.cc
src/remote_code_ptr.cc
src/ReplayCommand.cc
src/ReplaySession.cc
src/replay_syscall.cc
src/ReplayTask.cc
src/ReplayTimeline.cc
src/RerunCommand.cc
src/ReturnAddressList.cc
src/Scheduler.cc
src/SeccompFilterRewriter.cc
src/Session.cc
src/StdioMonitor.cc
src/Task.cc
src/ThreadGroup.cc
src/ThreadDb.cc
src/TraceFrame.cc
src/TraceStream.cc
src/VirtualPerfCounterMonitor.cc
src/util.cc
src/WaitStatus.cc
${CMAKE_CURRENT_BINARY_DIR}/rr_trace.capnp.c++
third-party/blake2/blake2b.c
)
set_source_files_properties(${RR_SOURCES}
PROPERTIES COMPILE_FLAGS ${RR_FLAGS})
function(post_build_executable target)
# grsecurity needs these. But if we add them ourselves, they may conflict
# with other flags added in other ways, and they all have to match :-(. So
# don't do this until a better solution presents itself
# add_custom_command(TARGET ${target}
# POST_BUILD
# COMMAND setfattr ARGS -n user.pax.flags -v m $<TARGET_FILE:${target}>)
endfunction(post_build_executable)
if(UNIX)
include(GNUInstallDirs)
else()
set(CMAKE_INSTALL_LIBDIR "lib")
set(CMAKE_INSTALL_BINDIR "bin")
set(CMAKE_INSTALL_DATADIR "share")
set(CMAKE_INSTALL_DOCDIR "${CMAKE_INSTALL_DATADIR}/doc")
set(CMAKE_INSTALL_INCLUDEDIR "include")
endif()
option(RR_BUILD_SHARED "Build the rr shared library as well as the binary (experimental).")
if(RR_BUILD_SHARED)
add_library(rr ${RR_SOURCES})
set_target_properties(rr PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
add_executable(rrbin src/main.cc)
set(RR_BIN rrbin)
post_build_executable(rrbin)
set_target_properties(rrbin PROPERTIES ENABLE_EXPORTS true OUTPUT_NAME rr)
set_target_properties(rrbin PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set_target_properties(rrbin PROPERTIES INSTALL_RPATH_USE_LINK_PATH true)
set_target_properties(brotli PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_link_libraries(rrbin rr)
install(TARGETS rr
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
else()
add_executable(rr ${RR_SOURCES} src/main.cc)
set_target_properties(rr PROPERTIES ENABLE_EXPORTS true)
post_build_executable(rr)
set(RR_BIN rr)
endif()
add_dependencies(rr Generated Pages)
option(strip "Strip debug info from rr binary")
if(strip)
set_target_properties(rr PROPERTIES LINK_FLAGS "-s")
endif()
target_link_libraries(rr
${CMAKE_DL_LIBS}
-lrt
brotli
)
if(staticlibs)
# Urgh ... this might not work for everyone, but there doesn't seem to be
# a way to persuade pkg-confing/pkg_check_modules to produce the right flags
target_link_libraries(rr -L/home/roc/lib -l:libcapnp.a -l:libkj.a)
# Note that this works for both clang++ and g++
set(CMAKE_CXX_FLAGS "-static-libstdc++ ${CMAKE_CXX_FLAGS}")
else()
target_link_libraries(rr ${CAPNP_LDFLAGS})
endif()
target_link_libraries(rrpreload
${CMAKE_DL_LIBS}
)
add_executable(rr_exec_stub src/exec_stub.c)
post_build_executable(rr_exec_stub)
set_target_properties(rr_exec_stub
PROPERTIES LINK_FLAGS "-static -nostartfiles -nodefaultlibs")
set_source_files_properties(src/exec_stub.c
COMPILE_FLAGS "-fno-stack-protector")
set(RR_GDB_RESOURCES
32bit-avx.xml
32bit-core.xml
32bit-linux.xml
32bit-sse.xml
64bit-avx.xml
64bit-core.xml
64bit-linux.xml
64bit-seg.xml
64bit-sse.xml
amd64-avx-linux.xml
amd64-linux.xml
i386-avx-linux.xml
i386-linux.xml
)
foreach(file ${RR_GDB_RESOURCES})
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/third-party/gdb/${file}"
"${CMAKE_CURRENT_BINARY_DIR}/share/rr/${file}"
COPYONLY)
install(FILES third-party/gdb/${file}
DESTINATION ${CMAKE_INSTALL_DATADIR}/rr)
endforeach(file)
foreach(file ${PRELOAD_SOURCE_FILES})
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/preload/${file}"
"${CMAKE_CURRENT_BINARY_DIR}/share/rr/src/preload/${file}"
COPYONLY)
install(FILES src/preload/${file}
DESTINATION ${CMAKE_INSTALL_DATADIR}/rr/src/preload)
endforeach(file)
install(PROGRAMS scripts/signal-rr-recording.sh
${CMAKE_CURRENT_BINARY_DIR}/bin/rr_page_64
${CMAKE_CURRENT_BINARY_DIR}/bin/rr_page_64_replay
${CMAKE_CURRENT_BINARY_DIR}/bin/rr_page_32
${CMAKE_CURRENT_BINARY_DIR}/bin/rr_page_32_replay
DESTINATION ${CMAKE_INSTALL_BINDIR})
install(PROGRAMS scripts/rr_completion
DESTINATION ${CMAKE_INSTALL_DATADIR}/bash-completion/completions RENAME rr)
install(TARGETS ${RR_BIN} rrpreload rr_exec_stub
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/rr
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/rr)
# Build 32-bit librrpreload on 64-bit builds.
# We copy the source files into '32' subdirectories in the output
# directory, so we can set different compile options on them.
# This sucks but I can't find a better way to get CMake to build
# the same source file in two different ways.
if(rr_32BIT AND rr_64BIT)
add_library(rrpreload_32)
foreach(file ${PRELOAD_SOURCE_FILES})
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/preload/${file}"
"${CMAKE_CURRENT_BINARY_DIR}/32/${file}"
COPYONLY)
endforeach(file)
foreach(file ${PRELOAD_FILES})
target_sources(rrpreload_32 PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/32/${file}")
set_source_files_properties("${CMAKE_CURRENT_BINARY_DIR}/32/${file}"
PROPERTIES COMPILE_FLAGS "-m32 ${RR_FLAGS_RELEASE}")
endforeach(file)
set_target_properties(rrpreload_32 PROPERTIES LINK_FLAGS "-m32 -nostartfiles")
target_link_libraries(rrpreload_32
${CMAKE_DL_LIBS}
)
foreach(file exec_stub.c)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/${file}"
"${CMAKE_CURRENT_BINARY_DIR}/32/${file}"
COPYONLY)
set_source_files_properties("${CMAKE_CURRENT_BINARY_DIR}/32/${file}"
PROPERTIES COMPILE_FLAGS "-m32 -fno-stack-protector")
endforeach(file)
add_executable(rr_exec_stub_32 32/exec_stub.c)
post_build_executable(rr_exec_stub_32)
set_target_properties(rr_exec_stub_32
PROPERTIES LINK_FLAGS "-static -nostartfiles -nodefaultlibs -m32")
install(TARGETS rrpreload_32 rr_exec_stub_32
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/rr
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/rr)
endif()
##--------------------------------------------------
## Testing
# A "basic test" consists of a foo.c source file. All basic tests use the
# same basic_test.run driver script. The test name is passed as an additional
# parameter to the driver script. This script just does
# "compare_test EXIT-SUCCESS", i.e. records and replays the program and verifies
# that the output of both runs is identical and contains EXIT-SUCCESS.
#
# NB: you must update this variable when adding a new test source
# file. The list is not generated automatically.
#
# Alphabetical, please.
set(BASIC_TESTS
64bit_child
_llseek
accept
acct
adjtimex
aio
alarm
alarm2
alsa_ioctl
arch_prctl
async_segv_ignored
at_threadexit
bad_ip
bad_syscall
barrier
big_buffers
block
block_open
brk
brk2
capget
chew_cpu
chmod
chown
clock
clock_nanosleep
clone
clone_bad_stack
clone_bad_tls
clone_fail
clone_file_range
clone_immediate_exit
clone_newflags
clone_parent
clone_untraced
cloned_sigmask
constructor
copy_file_range
creat_address_not_truncated
cross_arch
cwd_inaccessible
daemon
desched_blocking_poll
dup
doublesegv
epoll_create
epoll_create1
eventfd
exec_flags
exec_no_env
exec_self
exec_from_main_thread
exec_from_other_thread
exec_stopsig
exit_with_syscallbuf_signal
fadvise
fanotify
fault_in_code_page
fcntl_owner_ex
fcntl_dupfd
fcntl_rw_hints
fcntl_seals
fcntl_sig
fd_tracking_across_threads
fds_clean
flock
flock_ofd
flock2
fork_brk
fork_child_crash
fork_many
futex_pi
futex_priorities
fxregs
gdb_bogus_breakpoint
getcpu
getgroups
getpwnam
getrandom
setitimer
getsid
gettimeofday
grandchild_threads
grandchild_threads_main_running
grandchild_threads_thread_running
grandchild_threads_parent_alive
hle
inotify
int3
intr_futex_wait_restart
intr_poll
intr_ppoll
intr_pselect
intr_read_no_restart
intr_read_restart
intr_sleep
intr_sleep_no_restart
invalid_fcntl
invalid_ioctl
io
ioctl
ioctl_fs
ioctl_pty
ioctl_tty
join_threads
kcmp
keyctl
kill_newborn
kill_ptracee
legacy_ugid
lsl
madvise
madvise_free
map_fixed
map_shared_syscall
membarrier
memfd_create
mincore
mknod
mlock
mmap_adjacent_to_rr_usage
mmap_private
mmap_private_grow_under_map
mmap_ro
mmap_self_maps_shared
mmap_shared
mmap_shared_grow
mmap_shared_grow_under_map
mmap_shared_multiple
mmap_shared_subpage
mmap_shared_write
mmap_shared_write_fork
mmap_short_file
mmap_tmpfs
mmap_zero_size_fd
modify_ldt
mount_ns_exec
mprotect
mprotect_heterogenous
mprotect_none
mprotect_stack
mq
mremap
mremap_after_coalesce
mremap_grow
mremap_grow_shared
mremap_non_page_size
mremap_overwrite
mremap_private_grow_under_map
mremap_shrink
msg
msync
mtio
multiple_pending_signals
multiple_pending_signals_sequential
munmap_segv
munmap_discontinuous
nanosleep
netfilter
no_mask_timeslice
nscd
numa
old_fork
orphan_process
packet_mmap_disable
pause
perf_event
personality
pthread_rwlocks
poll_sig_race
ppoll
prctl
prctl_caps
prctl_deathsig
prctl_name
prctl_short_name
prctl_speculation_ctrl
prctl_tsc
privileged_net_ioctl
proc_fds
proc_mem
protect_rr_fds
prw
pthread_condvar_locking
ptrace
ptrace_attach_null_status
ptrace_attach_running
ptrace_attach_sleeping
ptrace_attach_stopped
ptrace_attach_thread_running
ptrace_breakpoint
ptrace_change_patched_syscall
ptrace_debug_regs
ptrace_exec
ptrace_exec32
ptrace_tls
ptrace_seize
ptrace_sigchld_blocked
ptrace_signals
ptrace_singlestep
ptrace_syscall
ptrace_syscall_clone_untraced
ptrace_sysemu
ptrace_sysemu_syscall
ptrace_trace_clone
ptrace_trace_exit
ptrace_traceme
ptracer_death
ptracer_death_multithread
ptracer_death_multithread_peer
# pivot_root ... disabled because it fails when run as root and does nothing otherwise
quotactl
rdtsc
read_nothing
readdir
read_large
read_oversize
readlink
readlinkat
readv
record_replay_subject
recvfrom
redzone_integrity
rename
rlimit
robust_futex
rusage
samask
save_data_fd
# sched_attr ... disabled since suitable headers are not widely available yet
sched_setaffinity
sched_setparam
sched_yield
sched_yield_to_lower_priority
scm_rights
scratch_read
seccomp
seccomp_clone_fail
seccomp_desched
seccomp_kill_exit
seccomp_null
seccomp_sigsys_args
seccomp_sigsys_sigtrap
seccomp_sigsys_syscallbuf
seccomp_tsync
seccomp_veto_exec
self_shebang
self_sigint
sem
send_block
sendfile
set_ptracer
set_tid_address
setgid
setgroups
setsid
setuid
shared_exec
shared_write
shm
shm_unmap
sigaction_old
sigaltstack
sigchld_interrupt_signal
sigcont
sighandler_fork
sighandler_mask
sigill
signal_deferred
signal_during_preload_init
signal_frame
signal_unstoppable
signalfd
sigprocmask
sigprocmask_ensure_delivery
sigprocmask_exec
sigprocmask_in_syscallbuf_sighandler
sigprocmask_rr_sigs
sigprocmask_syscallbuf
sigqueueinfo
sigreturn
sigreturn_reg
sigreturnmask
sigrt
sigstop
sigstop2
sigsuspend
sigtrap
simple
simple_threads_stress
sioc
sock_names_opts
spinlock_priorities
splice
stack_growth_after_syscallbuf
stack_growth_syscallbuf
stack_growth_with_guard
stack_invalid
stack_overflow
stack_overflow_altstack
stack_overflow_with_guard
statfs
statx
stdout_child
stdout_cloexec
stdout_dup
stdout_redirect
strict_priorities
switch_read
symlink
sync
sync_file_range
syscall_bp
syscall_in_writable_mem
syscallbuf_signal_reset
syscallbuf_signal_blocking
syscallbuf_sigstop
syscallbuf_timeslice
syscallbuf_timeslice2
sysconf
sysctl
sysemu_singlestep
sysfs
sysinfo
tgkill
thread_yield
timer
timerfd
times
truncate
tun
two_signals_with_mask
uname
unjoined_thread
unshare
utimes
vfork_flush
vfork_shared
video_capture
vm_readv_writev
wait
wait_sigstop
write_race
writev
xattr
zero_length_read
)
set(BASIC_CPP_TESTS
std_random
)
# A "test with program" consists of a foo.c source file and a foo.run driver
# script. See src/test/util.sh to learn how the .run files work.
#
# NB: you must update this variable when adding a new test source
# file. The list is not generated automatically.
#
# Alphabetical, please.
set(TESTS_WITH_PROGRAM
abort_nonmain
args
async_kill_with_threads
async_kill_with_threads_main_running
async_kill_with_threads_thread_running
async_segv
async_signal_syscalls
async_signal_syscalls2