2 * Copyright (c) 2008, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
11 * debug functions for the SAT solver
21 #include "solver_private.h"
22 #include "solverdebug.h"
32 solver_printruleelement(Solver *solv, int type, Rule *r, Id v)
34 Pool *pool = solv->pool;
38 s = pool->solvables + -v;
39 POOL_DEBUG(type, " !%s [%d]", pool_solvable2str(pool, s), -v);
43 s = pool->solvables + v;
44 POOL_DEBUG(type, " %s [%d]", pool_solvable2str(pool, s), v);
46 if (pool->installed && s->repo == pool->installed)
47 POOL_DEBUG(type, "I");
51 POOL_DEBUG(type, " (w1)");
53 POOL_DEBUG(type, " (w2)");
55 if (solv->decisionmap[s - pool->solvables] > 0)
56 POOL_DEBUG(type, " Install.level%d", solv->decisionmap[s - pool->solvables]);
57 if (solv->decisionmap[s - pool->solvables] < 0)
58 POOL_DEBUG(type, " Conflict.level%d", -solv->decisionmap[s - pool->solvables]);
59 POOL_DEBUG(type, "\n");
68 solver_printrule(Solver *solv, int type, Rule *r)
70 Pool *pool = solv->pool;
74 if (r >= solv->rules && r < solv->rules + solv->nrules) /* r is a solver rule */
75 POOL_DEBUG(type, "Rule #%d:", (int)(r - solv->rules));
77 POOL_DEBUG(type, "Rule:"); /* r is any rule */
79 POOL_DEBUG(type, " (disabled)");
80 POOL_DEBUG(type, "\n");
81 d = r->d < 0 ? -r->d - 1 : r->d;
85 /* print direct literal */
91 /* binary rule --> print w2 as second literal */
95 /* every other which is in d */
96 v = solv->pool->whatprovidesdata[d + i - 1];
99 solver_printruleelement(solv, type, r, v);
101 POOL_DEBUG(type, " next rules: %d %d\n", r->n1, r->n2);
105 solver_printruleclass(Solver *solv, int type, Rule *r)
107 Pool *pool = solv->pool;
108 Id p = r - solv->rules;
110 if (p < solv->learntrules)
111 if (MAPTST(&solv->weakrulemap, p))
112 POOL_DEBUG(type, "WEAK ");
113 if (solv->learntrules && p >= solv->learntrules)
114 POOL_DEBUG(type, "LEARNT ");
115 else if (p >= solv->bestrules && p < solv->bestrules_end)
116 POOL_DEBUG(type, "BEST ");
117 else if (p >= solv->choicerules && p < solv->choicerules_end)
118 POOL_DEBUG(type, "CHOICE ");
119 else if (p >= solv->infarchrules && p < solv->infarchrules_end)
120 POOL_DEBUG(type, "INFARCH ");
121 else if (p >= solv->duprules && p < solv->duprules_end)
122 POOL_DEBUG(type, "DUP ");
123 else if (p >= solv->jobrules && p < solv->jobrules_end)
124 POOL_DEBUG(type, "JOB ");
125 else if (p >= solv->updaterules && p < solv->updaterules_end)
126 POOL_DEBUG(type, "UPDATE ");
127 else if (p >= solv->featurerules && p < solv->featurerules_end)
128 POOL_DEBUG(type, "FEATURE ");
129 solver_printrule(solv, type, r);
133 solver_printproblem(Solver *solv, Id v)
135 Pool *pool = solv->pool;
141 solver_printruleclass(solv, SOLV_DEBUG_SOLUTIONS, solv->rules + v);
145 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "JOB %d\n", v);
146 jp = solv->ruletojob.elements;
147 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++, jp++)
150 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "- ");
151 solver_printrule(solv, SOLV_DEBUG_SOLUTIONS, r);
153 POOL_DEBUG(SOLV_DEBUG_SOLUTIONS, "ENDJOB\n");
158 solver_printwatches(Solver *solv, int type)
160 Pool *pool = solv->pool;
163 POOL_DEBUG(type, "Watches: \n");
164 for (counter = -(pool->nsolvables - 1); counter < pool->nsolvables; counter++)
165 POOL_DEBUG(type, " solvable [%d] -- rule [%d]\n", counter, solv->watches[counter + pool->nsolvables]);
169 solver_printdecisionq(Solver *solv, int type)
171 Pool *pool = solv->pool;
175 POOL_DEBUG(type, "Decisions:\n");
176 for (i = 0; i < solv->decisionq.count; i++)
178 p = solv->decisionq.elements[i];
180 POOL_DEBUG(type, "%d %d install %s, ", i, solv->decisionmap[p], pool_solvid2str(pool, p));
182 POOL_DEBUG(type, "%d %d conflict %s, ", i, -solv->decisionmap[-p], pool_solvid2str(pool, -p));
183 why = solv->decisionq_why.elements[i];
186 POOL_DEBUG(type, "forced by ");
187 solver_printruleclass(solv, type, solv->rules + why);
191 POOL_DEBUG(type, "chosen from ");
192 solver_printruleclass(solv, type, solv->rules - why);
195 POOL_DEBUG(type, "picked for some unknown reason.\n");
204 solver_printdecisions(Solver *solv)
206 Pool *pool = solv->pool;
207 Repo *installed = solv->installed;
208 Transaction *trans = solver_create_transaction(solv);
213 Queue recommendations;
217 POOL_DEBUG(SOLV_DEBUG_RESULT, "\n");
218 POOL_DEBUG(SOLV_DEBUG_RESULT, "transaction:\n");
221 for (i = 0; i < trans->steps.count; i++)
223 p = trans->steps.elements[i];
224 s = pool->solvables + p;
225 type = transaction_type(trans, p, SOLVER_TRANSACTION_SHOW_ACTIVE|SOLVER_TRANSACTION_SHOW_ALL|SOLVER_TRANSACTION_SHOW_OBSOLETES|SOLVER_TRANSACTION_SHOW_MULTIINSTALL);
228 case SOLVER_TRANSACTION_MULTIINSTALL:
229 POOL_DEBUG(SOLV_DEBUG_RESULT, " multi install %s", pool_solvable2str(pool, s));
231 case SOLVER_TRANSACTION_MULTIREINSTALL:
232 POOL_DEBUG(SOLV_DEBUG_RESULT, " multi reinstall %s", pool_solvable2str(pool, s));
234 case SOLVER_TRANSACTION_INSTALL:
235 POOL_DEBUG(SOLV_DEBUG_RESULT, " install %s", pool_solvable2str(pool, s));
237 case SOLVER_TRANSACTION_REINSTALL:
238 POOL_DEBUG(SOLV_DEBUG_RESULT, " reinstall %s", pool_solvable2str(pool, s));
240 case SOLVER_TRANSACTION_DOWNGRADE:
241 POOL_DEBUG(SOLV_DEBUG_RESULT, " downgrade %s", pool_solvable2str(pool, s));
243 case SOLVER_TRANSACTION_CHANGE:
244 POOL_DEBUG(SOLV_DEBUG_RESULT, " change %s", pool_solvable2str(pool, s));
246 case SOLVER_TRANSACTION_UPGRADE:
247 case SOLVER_TRANSACTION_OBSOLETES:
248 POOL_DEBUG(SOLV_DEBUG_RESULT, " upgrade %s", pool_solvable2str(pool, s));
250 case SOLVER_TRANSACTION_ERASE:
251 POOL_DEBUG(SOLV_DEBUG_RESULT, " erase %s", pool_solvable2str(pool, s));
258 case SOLVER_TRANSACTION_INSTALL:
259 case SOLVER_TRANSACTION_ERASE:
260 case SOLVER_TRANSACTION_MULTIINSTALL:
261 case SOLVER_TRANSACTION_MULTIREINSTALL:
262 POOL_DEBUG(SOLV_DEBUG_RESULT, "\n");
264 case SOLVER_TRANSACTION_REINSTALL:
265 case SOLVER_TRANSACTION_DOWNGRADE:
266 case SOLVER_TRANSACTION_CHANGE:
267 case SOLVER_TRANSACTION_UPGRADE:
268 case SOLVER_TRANSACTION_OBSOLETES:
269 transaction_all_obs_pkgs(trans, p, &iq);
272 POOL_DEBUG(SOLV_DEBUG_RESULT, " (obsoletes");
273 for (j = 0; j < iq.count; j++)
274 POOL_DEBUG(SOLV_DEBUG_RESULT, " %s", pool_solvid2str(pool, iq.elements[j]));
275 POOL_DEBUG(SOLV_DEBUG_RESULT, ")");
277 POOL_DEBUG(SOLV_DEBUG_RESULT, "\n");
285 POOL_DEBUG(SOLV_DEBUG_RESULT, "\n");
287 queue_init(&recommendations);
288 queue_init(&suggestions);
289 queue_init(&orphaned);
290 solver_get_recommendations(solv, &recommendations, &suggestions, 0);
291 solver_get_orphaned(solv, &orphaned);
292 if (recommendations.count)
294 POOL_DEBUG(SOLV_DEBUG_RESULT, "recommended packages:\n");
295 for (i = 0; i < recommendations.count; i++)
297 s = pool->solvables + recommendations.elements[i];
298 if (solv->decisionmap[recommendations.elements[i]] > 0)
300 if (installed && s->repo == installed)
301 POOL_DEBUG(SOLV_DEBUG_RESULT, " %s (installed)\n", pool_solvable2str(pool, s));
303 POOL_DEBUG(SOLV_DEBUG_RESULT, " %s (selected)\n", pool_solvable2str(pool, s));
306 POOL_DEBUG(SOLV_DEBUG_RESULT, " %s\n", pool_solvable2str(pool, s));
308 POOL_DEBUG(SOLV_DEBUG_RESULT, "\n");
311 if (suggestions.count)
313 POOL_DEBUG(SOLV_DEBUG_RESULT, "suggested packages:\n");
314 for (i = 0; i < suggestions.count; i++)
316 s = pool->solvables + suggestions.elements[i];
317 if (solv->decisionmap[suggestions.elements[i]] > 0)
319 if (installed && s->repo == installed)
320 POOL_DEBUG(SOLV_DEBUG_RESULT, " %s (installed)\n", pool_solvable2str(pool, s));
322 POOL_DEBUG(SOLV_DEBUG_RESULT, " %s (selected)\n", pool_solvable2str(pool, s));
325 POOL_DEBUG(SOLV_DEBUG_RESULT, " %s\n", pool_solvable2str(pool, s));
327 POOL_DEBUG(SOLV_DEBUG_RESULT, "\n");
331 POOL_DEBUG(SOLV_DEBUG_RESULT, "orphaned packages:\n");
332 for (i = 0; i < orphaned.count; i++)
334 s = pool->solvables + orphaned.elements[i];
335 if (solv->decisionmap[solv->orphaned.elements[i]] > 0)
336 POOL_DEBUG(SOLV_DEBUG_RESULT, " %s (kept)\n", pool_solvable2str(pool, s));
338 POOL_DEBUG(SOLV_DEBUG_RESULT, " %s (erased)\n", pool_solvable2str(pool, s));
340 POOL_DEBUG(SOLV_DEBUG_RESULT, "\n");
342 queue_free(&recommendations);
343 queue_free(&suggestions);
344 queue_free(&orphaned);
345 transaction_free(trans);
349 const char *id2strnone(Pool *pool, Id id)
351 return !id || id == 1 ? "(none)" : pool_id2str(pool, id);
355 transaction_print(Transaction *trans)
357 Pool *pool = trans->pool;
359 int i, j, mode, l, linel;
363 queue_init(&classes);
365 mode = SOLVER_TRANSACTION_SHOW_OBSOLETES | SOLVER_TRANSACTION_OBSOLETE_IS_UPGRADE;
366 transaction_classify(trans, mode, &classes);
367 for (i = 0; i < classes.count; i += 4)
369 Id class = classes.elements[i];
370 Id cnt = classes.elements[i + 1];
373 case SOLVER_TRANSACTION_ERASE:
374 POOL_DEBUG(SOLV_DEBUG_RESULT, "%d erased packages:\n", cnt);
376 case SOLVER_TRANSACTION_INSTALL:
377 POOL_DEBUG(SOLV_DEBUG_RESULT, "%d installed packages:\n", cnt);
379 case SOLVER_TRANSACTION_REINSTALLED:
380 POOL_DEBUG(SOLV_DEBUG_RESULT, "%d reinstalled packages:\n", cnt);
382 case SOLVER_TRANSACTION_DOWNGRADED:
383 POOL_DEBUG(SOLV_DEBUG_RESULT, "%d downgraded packages:\n", cnt);
385 case SOLVER_TRANSACTION_CHANGED:
386 POOL_DEBUG(SOLV_DEBUG_RESULT, "%d changed packages:\n", cnt);
388 case SOLVER_TRANSACTION_UPGRADED:
389 POOL_DEBUG(SOLV_DEBUG_RESULT, "%d upgraded packages:\n", cnt);
391 case SOLVER_TRANSACTION_VENDORCHANGE:
392 POOL_DEBUG(SOLV_DEBUG_RESULT, "%d vendor changes from '%s' to '%s':\n", cnt, id2strnone(pool, classes.elements[i + 2]), id2strnone(pool, classes.elements[i + 3]));
394 case SOLVER_TRANSACTION_ARCHCHANGE:
395 POOL_DEBUG(SOLV_DEBUG_RESULT, "%d arch changes from %s to %s:\n", cnt, pool_id2str(pool, classes.elements[i + 2]), pool_id2str(pool, classes.elements[i + 3]));
398 class = SOLVER_TRANSACTION_IGNORE;
401 if (class == SOLVER_TRANSACTION_IGNORE)
403 transaction_classify_pkgs(trans, mode, class, classes.elements[i + 2], classes.elements[i + 3], &pkgs);
406 for (j = 0; j < pkgs.count; j++)
408 Id p = pkgs.elements[j];
409 Solvable *s = pool->solvables + p;
414 case SOLVER_TRANSACTION_DOWNGRADED:
415 case SOLVER_TRANSACTION_UPGRADED:
416 s2 = pool->solvables + transaction_obs_pkg(trans, p);
417 POOL_DEBUG(SOLV_DEBUG_RESULT, " - %s -> %s\n", pool_solvable2str(pool, s), pool_solvable2str(pool, s2));
419 case SOLVER_TRANSACTION_VENDORCHANGE:
420 case SOLVER_TRANSACTION_ARCHCHANGE:
421 n = pool_id2str(pool, s->name);
423 if (l + linel > sizeof(line) - 3)
426 POOL_DEBUG(SOLV_DEBUG_RESULT, " %s\n", line);
430 if (l + linel > sizeof(line) - 3)
431 POOL_DEBUG(SOLV_DEBUG_RESULT, " %s\n", n);
436 strcpy(line + linel, ", ");
439 strcpy(line + linel, n);
444 POOL_DEBUG(SOLV_DEBUG_RESULT, " - %s\n", pool_solvable2str(pool, s));
449 POOL_DEBUG(SOLV_DEBUG_RESULT, " %s\n", line);
450 POOL_DEBUG(SOLV_DEBUG_RESULT, "\n");
452 queue_free(&classes);
457 solver_printproblemruleinfo(Solver *solv, Id probr)
459 Pool *pool = solv->pool;
460 Id dep, source, target;
461 SolverRuleinfo type = solver_ruleinfo(solv, probr, &source, &target, &dep);
463 POOL_DEBUG(SOLV_DEBUG_RESULT, "%s\n", solver_problemruleinfo2str(solv, type, source, target, dep));
467 solver_printprobleminfo(Solver *solv, Id problem)
469 solver_printproblemruleinfo(solv, solver_findproblemrule(solv, problem));
473 solver_printcompleteprobleminfo(Solver *solv, Id problem)
480 solver_findallproblemrules(solv, problem, &q);
481 for (i = 0; i < q.count; i++)
483 probr = q.elements[i];
484 if (!(probr >= solv->updaterules && probr < solv->updaterules_end) && !(probr >= solv->jobrules && probr < solv->jobrules_end))
490 for (i = 0; i < q.count; i++)
492 probr = q.elements[i];
493 if (nobad && ((probr >= solv->updaterules && probr < solv->updaterules_end) || (probr >= solv->jobrules && probr < solv->jobrules_end)))
495 solver_printproblemruleinfo(solv, probr);
500 static int illegals[] = {
501 POLICY_ILLEGAL_DOWNGRADE,
502 POLICY_ILLEGAL_NAMECHANGE,
503 POLICY_ILLEGAL_ARCHCHANGE,
504 POLICY_ILLEGAL_VENDORCHANGE,
509 solver_printsolution(Solver *solv, Id problem, Id solution)
511 Pool *pool = solv->pool;
515 while ((element = solver_next_solutionelement(solv, problem, solution, element, &p, &rp)) != 0)
519 /* for replacements we want to know why it was illegal */
520 Solvable *s = pool->solvables + p, *rs = pool->solvables + rp;
521 int illegal = policy_is_illegal(solv, s, rs, 0);
525 for (i = 0; illegals[i]; i++)
526 if ((illegal & illegals[i]) != 0)
528 POOL_DEBUG(SOLV_DEBUG_RESULT, " - allow %s\n", policy_illegal2str(solv, illegals[i], s, rs));
529 illegal ^= illegals[i];
535 POOL_DEBUG(SOLV_DEBUG_RESULT, " - %s\n", solver_solutionelement2str(solv, p, rp));
540 solver_printallsolutions(Solver *solv)
542 Pool *pool = solv->pool;
544 Id problem, solution;
546 POOL_DEBUG(SOLV_DEBUG_RESULT, "Encountered problems! Here are the solutions:\n\n");
549 while ((problem = solver_next_problem(solv, problem)) != 0)
552 POOL_DEBUG(SOLV_DEBUG_RESULT, "Problem %d:\n", pcnt);
553 POOL_DEBUG(SOLV_DEBUG_RESULT, "====================================\n");
555 solver_printprobleminfo(solv, problem);
557 solver_printcompleteprobleminfo(solv, problem);
559 POOL_DEBUG(SOLV_DEBUG_RESULT, "\n");
561 while ((solution = solver_next_solution(solv, problem, solution)) != 0)
563 solver_printsolution(solv, problem, solution);
564 POOL_DEBUG(SOLV_DEBUG_RESULT, "\n");
570 solver_printtrivial(Solver *solv)
572 Pool *pool = solv->pool;
580 for (p = 1, s = pool->solvables + p; p < solv->pool->nsolvables; p++, s++)
582 n = pool_id2str(pool, s->name);
583 if (strncmp(n, "patch:", 6) != 0 && strncmp(n, "pattern:", 8) != 0)
593 solver_trivial_installable(solv, &in, &out);
594 POOL_DEBUG(SOLV_DEBUG_RESULT, "trivial installable status:\n");
595 for (i = 0; i < in.count; i++)
596 POOL_DEBUG(SOLV_DEBUG_RESULT, " %s: %d\n", pool_solvid2str(pool, in.elements[i]), out.elements[i]);
597 POOL_DEBUG(SOLV_DEBUG_RESULT, "\n");