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 "solverdebug.h"
30 * create obsoletesmap from solver decisions
32 * for solvables in installed repo:
34 * p - one of the packages that obsolete us
36 * n - number of packages this package obsoletes
41 solver_create_decisions_obsoletesmap(Solver *solv)
43 Pool *pool = solv->pool;
44 Repo *installed = solv->installed;
45 Id p, *obsoletesmap = NULL;
49 obsoletesmap = (Id *)sat_calloc(pool->nsolvables, sizeof(Id));
52 for (i = 0; i < solv->decisionq.count; i++)
57 n = solv->decisionq.elements[i];
60 if (n == SYSTEMSOLVABLE)
62 s = pool->solvables + n;
63 if (s->repo == installed) /* obsoletes don't count for already installed packages */
65 noobs = solv->noobsoletes.size && MAPTST(&solv->noobsoletes, n);
66 FOR_PROVIDES(p, pp, s->name)
68 Solvable *ps = pool->solvables + p;
69 if (noobs && (s->name != ps->name || s->evr != ps->evr || s->arch != ps->arch))
71 if (!solv->implicitobsoleteusesprovides && s->name != ps->name)
73 if (pool->solvables[p].repo == installed && !obsoletesmap[p])
80 for (i = 0; i < solv->decisionq.count; i++)
85 n = solv->decisionq.elements[i];
88 if (n == SYSTEMSOLVABLE)
90 s = pool->solvables + n;
91 if (s->repo == installed) /* obsoletes don't count for already installed packages */
95 if (solv->noobsoletes.size && MAPTST(&solv->noobsoletes, n))
97 obsp = s->repo->idarraydata + s->obsoletes;
98 while ((obs = *obsp++) != 0)
100 FOR_PROVIDES(p, pp, obs)
102 if (!solv->obsoleteusesprovides && !pool_match_nevr(pool, pool->solvables + p, obs))
104 if (pool->solvables[p].repo == installed && !obsoletesmap[p])
117 solver_printruleelement(Solver *solv, int type, Rule *r, Id v)
119 Pool *pool = solv->pool;
123 s = pool->solvables + -v;
124 POOL_DEBUG(type, " !%s [%d]", solvable2str(pool, s), -v);
128 s = pool->solvables + v;
129 POOL_DEBUG(type, " %s [%d]", solvable2str(pool, s), v);
134 POOL_DEBUG(type, " (w1)");
136 POOL_DEBUG(type, " (w2)");
138 if (solv->decisionmap[s - pool->solvables] > 0)
139 POOL_DEBUG(type, " Install.level%d", solv->decisionmap[s - pool->solvables]);
140 if (solv->decisionmap[s - pool->solvables] < 0)
141 POOL_DEBUG(type, " Conflict.level%d", -solv->decisionmap[s - pool->solvables]);
142 POOL_DEBUG(type, "\n");
151 solver_printrule(Solver *solv, int type, Rule *r)
153 Pool *pool = solv->pool;
157 if (r >= solv->rules && r < solv->rules + solv->nrules) /* r is a solver rule */
158 POOL_DEBUG(type, "Rule #%d:", (int)(r - solv->rules));
160 POOL_DEBUG(type, "Rule:"); /* r is any rule */
162 POOL_DEBUG(type, " (disabled)");
163 POOL_DEBUG(type, "\n");
164 d = r->d < 0 ? -r->d - 1 : r->d;
168 /* print direct literal */
174 /* binary rule --> print w2 as second literal */
178 /* every other which is in d */
179 v = solv->pool->whatprovidesdata[d + i - 1];
182 solver_printruleelement(solv, type, r, v);
184 POOL_DEBUG(type, " next rules: %d %d\n", r->n1, r->n2);
188 solver_printruleclass(Solver *solv, int type, Rule *r)
190 Pool *pool = solv->pool;
191 Id p = r - solv->rules;
193 if (p < solv->learntrules)
194 if (MAPTST(&solv->weakrulemap, p))
195 POOL_DEBUG(type, "WEAK ");
196 if (p >= solv->learntrules)
197 POOL_DEBUG(type, "LEARNT ");
198 else if (p >= solv->infarchrules && p < solv->infarchrules_end)
199 POOL_DEBUG(type, "INFARCH ");
200 else if (p >= solv->duprules && p < solv->duprules_end)
201 POOL_DEBUG(type, "DUP ");
202 else if (p >= solv->jobrules && p < solv->jobrules_end)
203 POOL_DEBUG(type, "JOB ");
204 else if (p >= solv->updaterules && p < solv->updaterules_end)
205 POOL_DEBUG(type, "UPDATE ");
206 else if (p >= solv->featurerules && p < solv->featurerules_end)
207 POOL_DEBUG(type, "FEATURE ");
208 solver_printrule(solv, type, r);
212 solver_printproblem(Solver *solv, Id v)
214 Pool *pool = solv->pool;
220 solver_printruleclass(solv, SAT_DEBUG_SOLUTIONS, solv->rules + v);
224 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "JOB %d\n", v);
225 jp = solv->ruletojob.elements;
226 for (i = solv->jobrules, r = solv->rules + i; i < solv->jobrules_end; i++, r++, jp++)
229 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "- ");
230 solver_printrule(solv, SAT_DEBUG_SOLUTIONS, r);
232 POOL_DEBUG(SAT_DEBUG_SOLUTIONS, "ENDJOB\n");
237 solver_printwatches(Solver *solv, int type)
239 Pool *pool = solv->pool;
242 POOL_DEBUG(type, "Watches: \n");
243 for (counter = -(pool->nsolvables - 1); counter < pool->nsolvables; counter++)
244 POOL_DEBUG(type, " solvable [%d] -- rule [%d]\n", counter, solv->watches[counter + pool->nsolvables]);
252 solver_printdecisions(Solver *solv)
254 Pool *pool = solv->pool;
255 Repo *installed = solv->installed;
261 IF_POOLDEBUG (SAT_DEBUG_SCHUBI)
263 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions -----\n");
264 for (i = 0; i < solv->decisionq.count; i++)
266 p = solv->decisionq.elements[i];
267 solver_printruleelement(solv, SAT_DEBUG_SCHUBI, 0, p);
269 POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions end -----\n");
272 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
273 POOL_DEBUG(SAT_DEBUG_RESULT, "transaction:\n");
276 for (i = 0; i < solv->transaction.count; i += 2)
278 s = pool->solvables + solv->transaction.elements[i + 1];
279 switch(solv->transaction.elements[i])
281 case SOLVER_TRANSACTION_MULTIINSTALL:
282 POOL_DEBUG(SAT_DEBUG_RESULT, " multi install %s", solvable2str(pool, s));
284 case SOLVER_TRANSACTION_MULTIREINSTALL:
285 POOL_DEBUG(SAT_DEBUG_RESULT, " multi reinstall %s", solvable2str(pool, s));
287 case SOLVER_TRANSACTION_INSTALL:
288 POOL_DEBUG(SAT_DEBUG_RESULT, " install %s", solvable2str(pool, s));
290 case SOLVER_TRANSACTION_REINSTALL:
291 POOL_DEBUG(SAT_DEBUG_RESULT, " reinstall %s", solvable2str(pool, s));
293 case SOLVER_TRANSACTION_DOWNGRADE:
294 POOL_DEBUG(SAT_DEBUG_RESULT, " downgrade %s", solvable2str(pool, s));
296 case SOLVER_TRANSACTION_CHANGE:
297 POOL_DEBUG(SAT_DEBUG_RESULT, " change %s", solvable2str(pool, s));
299 case SOLVER_TRANSACTION_UPGRADE:
300 case SOLVER_TRANSACTION_RENAME:
301 POOL_DEBUG(SAT_DEBUG_RESULT, " upgrade %s", solvable2str(pool, s));
303 case SOLVER_TRANSACTION_ERASE:
304 POOL_DEBUG(SAT_DEBUG_RESULT, " erase %s", solvable2str(pool, s));
309 switch(solv->transaction.elements[i])
311 case SOLVER_TRANSACTION_INSTALL:
312 case SOLVER_TRANSACTION_ERASE:
313 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
315 case SOLVER_TRANSACTION_REINSTALL:
316 case SOLVER_TRANSACTION_DOWNGRADE:
317 case SOLVER_TRANSACTION_CHANGE:
318 case SOLVER_TRANSACTION_UPGRADE:
319 case SOLVER_TRANSACTION_RENAME:
320 solver_transaction_info(solv, solv->transaction.elements[i + 1], &iq);
323 POOL_DEBUG(SAT_DEBUG_RESULT, " (obsoletes");
324 for (j = 0; j < iq.count; j++)
325 POOL_DEBUG(SAT_DEBUG_RESULT, " %s", solvable2str(pool, pool->solvables + iq.elements[j]));
326 POOL_DEBUG(SAT_DEBUG_RESULT, ")");
328 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
336 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
338 if (solv->recommendations.count)
340 POOL_DEBUG(SAT_DEBUG_RESULT, "recommended packages:\n");
341 for (i = 0; i < solv->recommendations.count; i++)
343 s = pool->solvables + solv->recommendations.elements[i];
344 if (solv->decisionmap[solv->recommendations.elements[i]] > 0)
346 if (installed && s->repo == installed)
347 POOL_DEBUG(SAT_DEBUG_RESULT, " %s (installed)\n", solvable2str(pool, s));
349 POOL_DEBUG(SAT_DEBUG_RESULT, " %s (selected)\n", solvable2str(pool, s));
352 POOL_DEBUG(SAT_DEBUG_RESULT, " %s\n", solvable2str(pool, s));
354 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
357 if (solv->suggestions.count)
359 POOL_DEBUG(SAT_DEBUG_RESULT, "suggested packages:\n");
360 for (i = 0; i < solv->suggestions.count; i++)
362 s = pool->solvables + solv->suggestions.elements[i];
363 if (solv->decisionmap[solv->suggestions.elements[i]] > 0)
365 if (installed && s->repo == installed)
366 POOL_DEBUG(SAT_DEBUG_RESULT, " %s (installed)\n", solvable2str(pool, s));
368 POOL_DEBUG(SAT_DEBUG_RESULT, " %s (selected)\n", solvable2str(pool, s));
371 POOL_DEBUG(SAT_DEBUG_RESULT, " %s\n", solvable2str(pool, s));
373 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
375 if (solv->orphaned.count)
377 POOL_DEBUG(SAT_DEBUG_RESULT, "orphaned packages:\n");
378 for (i = 0; i < solv->orphaned.count; i++)
380 s = pool->solvables + solv->orphaned.elements[i];
381 if (solv->decisionmap[solv->orphaned.elements[i]] > 0)
382 POOL_DEBUG(SAT_DEBUG_RESULT, " %s (kept)\n", solvable2str(pool, s));
384 POOL_DEBUG(SAT_DEBUG_RESULT, " %s (erased)\n", solvable2str(pool, s));
386 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
391 solver_printprobleminfo(Solver *solv, Queue *job, Id problem)
393 Pool *pool = solv->pool;
395 Id dep, source, target;
398 probr = solver_findproblemrule(solv, problem);
399 switch (solver_problemruleinfo(solv, job, probr, &dep, &source, &target))
401 case SOLVER_RULE_DISTUPGRADE:
402 s = pool_id2solvable(pool, source);
403 POOL_DEBUG(SAT_DEBUG_RESULT, "%s does not belong to a distupgrade repository\n", solvable2str(pool, s));
405 case SOLVER_RULE_INFARCH:
406 s = pool_id2solvable(pool, source);
407 POOL_DEBUG(SAT_DEBUG_RESULT, "%s has inferior architecture\n", solvable2str(pool, s));
409 case SOLVER_RULE_UPDATE:
410 s = pool_id2solvable(pool, source);
411 POOL_DEBUG(SAT_DEBUG_RESULT, "problem with installed package %s\n", solvable2str(pool, s));
413 case SOLVER_RULE_JOB:
414 POOL_DEBUG(SAT_DEBUG_RESULT, "conflicting requests\n");
416 case SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP:
417 POOL_DEBUG(SAT_DEBUG_RESULT, "nothing provides requested %s\n", dep2str(pool, dep));
419 case SOLVER_RULE_RPM:
420 POOL_DEBUG(SAT_DEBUG_RESULT, "some dependency problem\n");
422 case SOLVER_RULE_RPM_NOT_INSTALLABLE:
423 s = pool_id2solvable(pool, source);
424 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s is not installable\n", solvable2str(pool, s));
426 case SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP:
427 s = pool_id2solvable(pool, source);
428 POOL_DEBUG(SAT_DEBUG_RESULT, "nothing provides %s needed by %s\n", dep2str(pool, dep), solvable2str(pool, s));
430 case SOLVER_RULE_RPM_SAME_NAME:
431 s = pool_id2solvable(pool, source);
432 s2 = pool_id2solvable(pool, target);
433 POOL_DEBUG(SAT_DEBUG_RESULT, "cannot install both %s and %s\n", solvable2str(pool, s), solvable2str(pool, s2));
435 case SOLVER_RULE_RPM_PACKAGE_CONFLICT:
436 s = pool_id2solvable(pool, source);
437 s2 = pool_id2solvable(pool, target);
438 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s conflicts with %s provided by %s\n", solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
440 case SOLVER_RULE_RPM_PACKAGE_OBSOLETES:
441 s = pool_id2solvable(pool, source);
442 s2 = pool_id2solvable(pool, target);
443 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s obsoletes %s provided by %s\n", solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
445 case SOLVER_RULE_RPM_IMPLICIT_OBSOLETES:
446 s = pool_id2solvable(pool, source);
447 s2 = pool_id2solvable(pool, target);
448 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s implicitely obsoletes %s provided by %s\n", solvable2str(pool, s), dep2str(pool, dep), solvable2str(pool, s2));
450 case SOLVER_RULE_RPM_PACKAGE_REQUIRES:
451 s = pool_id2solvable(pool, source);
452 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s requires %s, but none of the providers can be installed\n", solvable2str(pool, s), dep2str(pool, dep));
454 case SOLVER_RULE_RPM_SELF_CONFLICT:
455 s = pool_id2solvable(pool, source);
456 POOL_DEBUG(SAT_DEBUG_RESULT, "package %s conflicts with %s provided by itself\n", solvable2str(pool, s), dep2str(pool, dep));
458 case SOLVER_RULE_UNKNOWN:
459 case SOLVER_RULE_FEATURE:
460 case SOLVER_RULE_LEARNT:
461 POOL_DEBUG(SAT_DEBUG_RESULT, "bad rule type\n");
467 solver_printsolutions(Solver *solv, Queue *job)
469 Pool *pool = solv->pool;
471 Id p, rp, how, what, select;
472 Id problem, solution, element;
475 POOL_DEBUG(SAT_DEBUG_RESULT, "Encountered problems! Here are the solutions:\n\n");
478 while ((problem = solver_next_problem(solv, problem)) != 0)
480 POOL_DEBUG(SAT_DEBUG_RESULT, "Problem %d:\n", pcnt++);
481 POOL_DEBUG(SAT_DEBUG_RESULT, "====================================\n");
482 solver_printprobleminfo(solv, job, problem);
483 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
485 while ((solution = solver_next_solution(solv, problem, solution)) != 0)
488 while ((element = solver_next_solutionelement(solv, problem, solution, element, &p, &rp)) != 0)
490 if (p == SOLVER_SOLUTION_JOB)
492 /* job, rp is index into job queue */
493 how = job->elements[rp - 1];
494 what = job->elements[rp];
495 select = how & SOLVER_SELECTMASK;
496 switch (how & SOLVER_JOBMASK)
499 if (select == SOLVER_SOLVABLE && solv->installed && pool->solvables[what].repo == solv->installed)
500 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not keep %s installed\n", solvable2str(pool, pool->solvables + what));
501 else if (select == SOLVER_SOLVABLE_PROVIDES)
502 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install a solvable %s\n", solver_select2str(solv, select, what));
504 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install %s\n", solver_select2str(solv, select, what));
507 if (select == SOLVER_SOLVABLE && !(solv->installed && pool->solvables[what].repo == solv->installed))
508 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not forbid installation of %s\n", solvable2str(pool, pool->solvables + what));
509 else if (select == SOLVER_SOLVABLE_PROVIDES)
510 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall all solvables %s\n", solver_select2str(solv, select, what));
512 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall %s\n", solver_select2str(solv, select, what));
515 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install most recent version of %s\n", solver_select2str(solv, select, what));
518 POOL_DEBUG(SAT_DEBUG_RESULT, "- do not lock %s\n", solver_select2str(solv, select, what));
521 POOL_DEBUG(SAT_DEBUG_RESULT, "- do something different\n");
525 else if (p == SOLVER_SOLUTION_INFARCH)
527 s = pool->solvables + rp;
528 if (solv->installed && s->repo == solv->installed)
529 POOL_DEBUG(SAT_DEBUG_RESULT, "- keep %s despite the inferior architecture\n", solvable2str(pool, s));
531 POOL_DEBUG(SAT_DEBUG_RESULT, "- install %s despite the inferior architecture\n", solvable2str(pool, s));
533 else if (p == SOLVER_SOLUTION_DISTUPGRADE)
535 s = pool->solvables + rp;
536 if (solv->installed && s->repo == solv->installed)
537 POOL_DEBUG(SAT_DEBUG_RESULT, "- keep obsolete %s\n", solvable2str(pool, s));
539 POOL_DEBUG(SAT_DEBUG_RESULT, "- install %s from excluded repository\n", solvable2str(pool, s));
543 /* policy, replace p with rp */
544 s = pool->solvables + p;
545 sd = rp ? pool->solvables + rp : 0;
546 if (s == sd && solv->distupgrade)
548 POOL_DEBUG(SAT_DEBUG_RESULT, "- keep obsolete %s\n", solvable2str(pool, s));
553 if (!solv->allowdowngrade && evrcmp(pool, s->evr, sd->evr, EVRCMP_MATCH_RELEASE) > 0)
555 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow downgrade of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
558 if (!solv->allowarchchange && s->name == sd->name && s->arch != sd->arch && policy_illegal_archchange(solv, s, sd))
560 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow architecture change of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
563 if (!solv->allowvendorchange && s->name == sd->name && s->vendor != sd->vendor && policy_illegal_vendorchange(solv, s, sd))
566 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow vendor change from '%s' (%s) to '%s' (%s)\n", id2str(pool, s->vendor), solvable2str(pool, s), id2str(pool, sd->vendor), solvable2str(pool, sd));
568 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow vendor change from '%s' (%s) to no vendor (%s)\n", id2str(pool, s->vendor), solvable2str(pool, s), solvable2str(pool, sd));
572 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow replacement of %s with %s\n", solvable2str(pool, s), solvable2str(pool, sd));
576 POOL_DEBUG(SAT_DEBUG_RESULT, "- allow deinstallation of %s\n", solvable2str(pool, s));
581 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
587 solver_printtrivial(Solver *solv)
589 Pool *pool = solv->pool;
597 for (p = 1, s = pool->solvables + p; p < solv->pool->nsolvables; p++, s++)
599 n = id2str(pool, s->name);
600 if (strncmp(n, "patch:", 6) != 0 && strncmp(n, "pattern:", 8) != 0)
610 solver_trivial_installable(solv, &in, &out);
611 POOL_DEBUG(SAT_DEBUG_RESULT, "trivial installable status:\n");
612 for (i = 0; i < in.count; i++)
613 POOL_DEBUG(SAT_DEBUG_RESULT, " %s: %d\n", solvable2str(pool, pool->solvables + in.elements[i]), out.elements[i]);
614 POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
620 solver_select2str(Solver *solv, Id select, Id what)
622 Pool *pool = solv->pool;
625 if (select == SOLVER_SOLVABLE)
626 return solvable2str(pool, pool->solvables + what);
627 if (select == SOLVER_SOLVABLE_NAME)
628 return dep2str(pool, what);
629 if (select == SOLVER_SOLVABLE_PROVIDES)
631 s = dep2str(pool, what);
632 b = pool_alloctmpspace(pool, 11 + strlen(s));
633 sprintf(b, "providing %s", s);
636 if (select == SOLVER_SOLVABLE_ONE_OF)
641 while ((p = pool->whatprovidesdata[what++]) != 0)
643 s = solvable2str(pool, pool->solvables + p);
644 b2 = pool_alloctmpspace(pool, strlen(b) + strlen(s) + 3);
645 sprintf(b2, "%s, %s", b, s);
648 return *b ? b + 2 : "nothing";
650 return "unknown job select";